2014-09-21 86 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"