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