Comments (17)
I'm facing the same issue.
At first, I tried the simple $scope.videos = Youtube.search(...)
in my controller. Then I noticed the GAPI.init()
method in the source, which sets the oauthToken
variable. So I decided to wrap the search
call like this -:
GAPI.init()
.then(function(){
$scope.videos = Youtube.search({part: 'snippet', q: 'Ayy lmao'});
}, function(){ console.log('Something went wrong yes?'); });
On doing this, I get the following stack trace -:
TypeError: Cannot read property 'authorize' of undefined
at Function.GAPI.init (http://localhost:8100/lib/ngGAPI/gapi.js:409:16)
at new <anonymous> (http://localhost:8100/js/controllers.js:15:10)
at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12884:17)
at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12892:27)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17161:28
....
....
All this boils down to the same problem that I was trying to avoid before using this library - it appears that the gapi
object is not yet populated, and so gapi.auth
turns out to be undefined.
The issue remains the same even if I try to keep the client.js
script on my local. Unless gapi
finishes loading, its properties will be undefined - ref: http://stackoverflow.com/questions/12874491/why-is-gapi-client-from-google-plus-api-undefined
I've issued a hack in my ionic app to get this to work. Basically, we cannot avoid the onload
parameter in the JS.
<!-- Hack because we can't avoid this shitty onload parameter -->
<!-- Need to think of better way -->
<script type="text/javascript">
function onClientLoad(){
gapi.client.load('youtube', 'v3', function(){
console.log("Setting API key");
gapi.client.setApiKey('your-api-key');
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=onClientLoad"></script>
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- ngGAPI script -->
<script src="lib/ngGAPI/gapi.js"></script>
The order of the script tags is very, very important. First we define what we do when the client script loads completely. Then we have the line for the client script.
Then we begin our regular angular dependency lineup. A note to ionic users: refreshing your app in the browser (during development) is not sufficient - you need to re-serve the app to avoid the undefined errors - probably because of ionic's caching.
Further note to the poor souls who got all those access denied errors despite having set the client ID and the API key properly - Google no longer offers the free edition of Google Apps. To register your app with them and define the API scopes that you can use, you'll have to pay for an account. ref: http://stackoverflow.com/questions/21452842/access-denied-requested-scopes-not-allowed-for-google-service-account
from nggapi.
Google changes the name of the property that holds the object with the access_token from hg to Zi.
If you are accessing that directly you should change your code, for example
var objectWithAccessToken = res.hg || res.Zi;
this.onAuthResult('Google', objectWithAccessToken.access_token);
And yes I know we are not supposed to touch that object directly in the first place.
from nggapi.
I got the same error
TypeError: Cannot read property 'access_token' of undefined
at oauthHeader (http://localhost:8100/lib/ngGAPI/gapi.js:113:73)
at request (http://localhost:8100/lib/ngGAPI/gapi.js:129:7)
at GAPI.get (http://localhost:8100/lib/ngGAPI/gapi.js:170:14)
at GAPI.Youtube.search (http://localhost:8100/lib/ngGAPI/gapi.js:455:22)
from nggapi.
Same Error :(
from nggapi.
Anyone found a fix?
from nggapi.
I'm also getting same error. Did you guys got any fix for this? Kindly respond..
from nggapi.
Seeing the exact same issue, tried changing the loading of the scripts but no luck
from nggapi.
Any updates on this issue? Having the same problem.
from nggapi.
Problem is gapi (from google api client library - https://apis.google.com/js/client.js) not fully loaded when GAPI.init invoked. I create pull request #19 with wrapped GAPI.init into gapi.loaded method
from nggapi.
So this fixes the problem @nastradamus39 ?
from nggapi.
@arielcr Yep. But i catch "Cannot read property 'access_token' of undefined" because of bad keys.
access_token set only after success response - https://github.com/christiansmith/ngGAPI/blob/master/gapi.js#L386
from nggapi.
Already i catch another strange bug.
In gapi.auth.authorize({
client_id: app.clientId,
scope: app.scopes,
"immediate": true
}, onAuth
);
If "immediate" set to true - authorization popup not shows. And we got error above.
If "immediate" set to false - all ok.
from nggapi.
Still not working using your fix @nastradamus39
from nggapi.
@arielcr I had the same issue after implementing @nastradamus39 's solution but then tried with an Incognito window and it worked. After that I tried with a hard reload and it seems to be working in a regular window.
I recommend immediate: true for the initial authorize call and immediate: false for the one inside the onAuth callback.
from nggapi.
Hi, I'm working on an Ionic Project and I try to use this plugin, but I have the same problem ... This is the same with @nastradamus39's changes.
Thank you
Guillaume
from nggapi.
the response has now changed to "res.uc.access_token"
from nggapi.
@Sariputta Thanks, I have a legacy system that depends on this that I need to keep running for a few more months.
from nggapi.
Related Issues (15)
- Upload functionality not working as expected
- There is no way to auth with immediate: false (for first time app authorization)
- TypeError: Youtube.search is not a function
- TypeScript definition HOT 1
- Not able to download via bower HOT 1
- Unable to call init() on GAPI HOT 2
- Authenticate window on Android
- Unknown provider: DriveProvider <- Drive <- VideoController
- Login attempt failed. Attempted to login 4 times. HOT 1
- First time clicking button to do oauth triggers pop-up blocker HOT 2
- Logged in HOT 1
- How to save authentification HOT 3
- adding "main":"gapi.js", to bower will help in auto injection
- Secure apiKey & clientId HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nggapi.