Coder Social home page Coder Social logo

Comments (17)

PritishC avatar PritishC commented on July 22, 2024 3

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.

ofirgeller avatar ofirgeller commented on July 22, 2024 1

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.

clowNay avatar clowNay commented on July 22, 2024

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.

hughred22 avatar hughred22 commented on July 22, 2024

Same Error :(

from nggapi.

divir94 avatar divir94 commented on July 22, 2024

screen shot 2015-05-10 at 9 08 51 pm

Anyone found a fix?

from nggapi.

itsanmax avatar itsanmax commented on July 22, 2024

I'm also getting same error. Did you guys got any fix for this? Kindly respond..

from nggapi.

maallen avatar maallen commented on July 22, 2024

Seeing the exact same issue, tried changing the loading of the scripts but no luck

from nggapi.

arielcr avatar arielcr commented on July 22, 2024

Any updates on this issue? Having the same problem.

from nggapi.

nastradamus39 avatar nastradamus39 commented on July 22, 2024

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.

arielcr avatar arielcr commented on July 22, 2024

So this fixes the problem @nastradamus39 ?

from nggapi.

nastradamus39 avatar nastradamus39 commented on July 22, 2024

@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.

nastradamus39 avatar nastradamus39 commented on July 22, 2024

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.

arielcr avatar arielcr commented on July 22, 2024

Still not working using your fix @nastradamus39

from nggapi.

ChristianMMacy avatar ChristianMMacy commented on July 22, 2024

@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.

guirou62 avatar guirou62 commented on July 22, 2024

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.

jinghanng avatar jinghanng commented on July 22, 2024

the response has now changed to "res.uc.access_token"

from nggapi.

ofirgeller avatar ofirgeller commented on July 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.