我想自定义范围,只允许"电子邮件"和"个人资料",没有" openid"
因为我想让它只要求访问电子邮件和基本个人资料信息。
我尝试使用meta:
<meta name="google-signin-scope" content="email profile">
或js:
gapi.auth2.init({
client_id: 'xxxxxxxxx.apps.googleusercontent.com',
scope: 'email profile'
});
但它不起作用:在生成的URL中总是有&#34; openid&#34;范围...
我怎样才能重置&#34;范围,只允许我想要的东西?
答案 0 :(得分:3)
BasicProfile需要&#39;个人资料电子邮件openid&#39;作用域。
您可以停用基本个人资料,只需要发送个人资料&#39;的范围:
<meta name="google-signin-fetch_basic_profile" content="false">
<meta name="google-signin-scope" content="profile email">
请注意,在这种情况下,GoogleUser.getBasicProfile()将返回null。你必须手动获取&#39; profile&#39;和&#39;电子邮件&#39;数据
完全正常的示例(您必须将YOUR_CLIENT_ID替换为您的实际client_id):
<html>
<head>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID">
<meta name="google-signin-fetch_basic_profile" content="false">
<meta name="google-signin-scope" content="profile email">
</head>
<body>
<script>
function requestEmailData() {
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
// Shows user email
console.log(resp.email);
})
});
}
function requestProfileData() {
gapi.client.load('plus', 'v1', function() {
gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
// Shows profile information
console.log(resp);
})
});
}
function onSuccess() {
gapi.load('client', function() {
// based on http://stackoverflow.com/a/15384981
requestEmailData();
requestProfileData();
});
}
</script>
<div class="g-signin2" data-onsuccess="onSuccess"></div>
<script src="https://apis.google.com/js/platform.js?onload=onLoad" async defer></script>
</body>
</html>
请注意,您必须在开发者控制台中启用Google+ API才能请求&#39;个人资料&#39;数据。要做到这一点