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: .me
And the Email i can get from the scope: .email
But how I can use them both in the same application?
My code is:
scopes = '.me .email';
gapi.signin.render('StartGoogleBtn', {
'callback': 'onSignInCallback',
'clientid': clientId,
'cookiepolicy': 'single_host_origin',
'scope': scopes
});
What scopes should be? Thanks :)
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 :)
Share Improve this question edited Sep 22, 2014 at 8:29 roev asked Sep 21, 2014 at 22:01 roevroev 1,2772 gold badges18 silver badges29 bronze badges3 Answers
Reset to default 29Just 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.
This is how you exactly right the scope step by step this is the format you should follow while writing the scope on Google app script in appscript.json
{ "oauthScopes": ["https://www.googleapis.com/auth/spreadsheets" , "https://www.googleapis.com/auth/script.send_mail"] }