gapi.auth.authorize returns error message

3,923 views
Skip to first unread message

Marcos Pereira

unread,
Aug 1, 2014, 7:06:05 AM8/1/14
to google-api-jav...@googlegroups.com
 Hey everyone, I am doing a request to the google api with gapi.auth.authorize, and on the callback, the authResult object is pretty weird, giving me this:

 TypeError {stack: (...), message: "Cannot read property 'scope' of null"} message: "Cannot read property 'scope' of null" stack: "TypeError: Cannot read property 'scope' of null↵

 I have tried to search for this error but didn't find any significant solution. The code that produces this error is: (using angularJS):

 $window.gapi.auth.authorize({
        clientid
: 'my-client-id',
        scope
: 'https://www.googleapis.com/auth/plus.login',
        immediate
: true
     
}, function (authResult) {
       
if (authResult && authResult.access_token){
         
// never gets called
       
} else {
          console
.log(authResult);
         
// authResult gets logged and is the error message I mentioned
       
}
     
});

   Logging the $window.gapi.auth object returns an object that contains the authorize property, so the issue can't be that the library isn't properly loaded. Honestly, I've ran into several errors already using google apis and the documentation has been very poor, incomplete, and lacking a lot of details so far. I wasn't expecting this from a company such as google. This is really sad and frustrating, and I'm pretty close to just giving up on implementing google as an authentication option on my app.

 Thanks in advance for any and all help you can give me!

Marcos Pereira

unread,
Aug 1, 2014, 8:09:51 AM8/1/14
to google-api-jav...@googlegroups.com
 Seriously google. Seriously.
 
 The problem was the clientid parameter. It's supposed to be client_id. Now please tell me how "Cannot read property 'scope' of null"
is in any way related to that.

Claus F. Strasburger

unread,
Sep 25, 2014, 11:32:57 AM9/25/14
to google-api-jav...@googlegroups.com
As a sidenote: The same thing happens when the clientid is null or undefined.

Wiwit Aditya

unread,
Apr 1, 2015, 11:28:17 AM4/1/15
to google-api-jav...@googlegroups.com
Hi,
maybe it's kinda late answer but when i search with keywords
"google api Cannot read property 'scope' of null"

this link still on first result and didn't resolve the problem, i hope it will help the others

My goal is need to fetch profile picture url when the user sign into my app through google sign-in using api gapi.auth.signIn then gapi.client.plus.people.get to signin and then get the url. And it doing correctly

But the problem is was when the user still sign-in on google and still sign on my app i must doing the same thing above, (the process above will show the user consent popup window whatever we already have access or not) the popup window it self is a bit annoying

Then i use gapi.client.plus.people.get and got the error result
"google api Cannot read property 'scope' of null"

After couple hours i trying, i already resolve the problem using gapi.signin.render, here is the code


// preparing parameter
var additionalParams = {
 
"clientid" : googleClientId,
 
"callback" : signinCallback,
 
"cookiepolicy": "single_host_origin",
};
/*
 * User has never beed sign-in into our app  
 */


// firstly, the user must click sign-in button
gapi
.auth.signIn(additionalParams);
// then it would call the callback


function signinCallback(authResult) {
 
if (authResult['status']['signed_in']) {
 
// load the 'plus' resource
 gapi
.client.load('plus', 'v1', fetchGoogleProfile);
 
// then it would call the callback
 
}
}
function fetchGoogleProfile() {
 
// after loaded then get the user profile
 gapi
.client.plus.people.get({userId: 'me'}).execute(processResponse);
 
// then it would call the callback
}
function processResponse(resp) {
 resp
.image.url // here the image url
}
/*
 * User already sign-in on our app and on google
 *  and need to fetch image url again without show the popup
 */

// preparing the element for render purpose, in some place where the user would never see
 
<span id="googleButton"/>
// call this api
gapi
.signin.render('googleButton', additionalParams);
// then it would call the additionalParams function and we can fetch the url again


Reply all
Reply to author
Forward
0 new messages