2014-09-21 38 views
2

我想在Google API JavaScript中使用多个示波器。 我想要做的是让用户电子邮件&名称。Google API多个示波器

名,我可以从范围得到:https://www.googleapis.com/auth/plus.me

和电子邮件,我可以从范围得到:https://www.googleapis.com/auth/userinfo.email

但我怎么可以在同一应用程序中使用他们两个?

我的代码是:

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 
    }); 

应该是什么范围?谢谢:)

回答

0

我会在我的答案前说我没有使用Javascript版本。我正在使用Java库,它允许我通过传递一个包含我想要的范围的字符串列表来设置范围。

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(); 

假设Javascript库的工作方式类似于在Java一个,你应该能够使你scopes变量的字符串数组添加多个范围。

3

只是猜测,但尝试用双引号围绕它分隔空间。这就是OAuth 2所要求的,当我为客户端编写代码时,我会自动正确处理该场景。我认为它只是通过命令传递的。这对我来说很有用。

scopes = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me"