我想在Google API JavaScript中使用多个范围。 我想要做的就是让用户使用Email&名称。
我可以从范围中获取姓名: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 :(得分:10)
只是猜测,但尝试使用围绕它的双引号分隔空格。这就是OAuth 2所要求的,当我为客户端编写代码时,我会自动正确地处理该场景。我认为它只是被命令通过。这对我有用。
SELECT i.instagrammer_id, CONCAT(i.first_name,' ',i.last_name) AS instagrammer_name, FLOOR(DATEDIFF (NOW(), i.date_of_birth)/365) AS age, i.date_of_birth, i.gender, i.email, i.created_date, GROUP_CONCAT(b.name_en) AS industrie_branch, coalesce(c.long_name, '') AS long_name, s.social_id, st.followers
FROM instagrammer AS i
LEFT JOIN social_login AS s ON s.instagrammer_id = i.instagrammer_id
LEFT JOIN industries_branches b ON FIND_IN_SET(b.industrie_branch_id, i.industrie_branch)
LEFT JOIN country_data c ON c.short_name = i.based_in_country
LEFT JOIN (SELECT instagrammer_id, max(created_date) as maxdate from statistic_instagrammer_detail group by instagrammer_id) t on i.instagrammer_id=t.instagrammer_id
LEFT JOIN statistic_instagrammer_detail st ON i.instagrammer_id=st.instagrammer_id and t.maxdate=st.created_date
WHERE i.status IS NOT NULL
GROUP BY i.instagrammer_id
ORDER BY instagrammer_name DESC
答案 1 :(得分:1)
我会在答案前说我还没有使用过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
变量成为字符串数组来添加多个范围。
答案 2 :(得分:0)
这是您逐步正确调整范围的方式,这是在Google应用程序脚本中的appscript.json中写入范围时应遵循的格式
{ “ oauthScopes”:[“ https://www.googleapis.com/auth/spreadsheets”,“ https://www.googleapis.com/auth/script.send_mail”] }