I want to use multiple scopes in the Google API JavaScript. What I'm trying to do is to get the user Email & Name.
The Name i can get from the scope: https://www.googleapis.com/auth/plus.me
And the Email i can get from the scope: https://www.googleapis.com/auth/userinfo.email
But how I can use them both in the same application?
My code is:
scopes = 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email';
gapi.signin.render('StartGoogleBtn', {
'callback': 'onSignInCallback',
'clientid': clientId,
'cookiepolicy': 'single_host_origin',
'scope': scopes
});
What scopes should be? Thanks :)
Just guessing, but try space delimited with double-quotes surrounding it. That's what OAuth 2 calls for and when I wrote the code for the client I made it automatically deal with that scenario correctly. I assume it'd just get passed through by the command.That's work for me.
scopes = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me"
I'll preface my answer by saying that I haven't used the Javascript version. I'm using the Java library, which lets me set the scopes by passing a list of strings containing the scopes I want.
List<String> SCOPES = Arrays.asList(
DirectoryScopes.ADMIN_DIRECTORY_GROUP, //https://www.googleapis.com/auth/admin.directory.group
DirectoryScopes.ADMIN_DIRECTORY_USER, //https://www.googleapis.com/auth/admin.directory.user
DriveScopes.DRIVE //https://www.googleapis.com/auth/drive
);
credential = new GoogleCredential.Builder()
.setTransport(httpTransport).setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountId)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(p12File)
.setServiceAccountUser(adminUser).build();
Assuming the Javascript library works similarly to the Java one, you should be able to add multiple scopes by making your scopes
variable an array of Strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With