我使用oauth2.0进行了accessstoken.我能够获得人名,性别等,但我无法获得用户的电子邮件地址.
任何人都可以粘贴一些示例代码或有关如何从google plus API获取电子邮件地址的任何建议吗?
如果他们专门授权您的应用程序查看其电子邮件地址,则可以检索用户的电子邮件地址.
将范围设置为:
https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email
Run Code Online (Sandbox Code Playgroud)
JavaScript调用如下所示:
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
// Shows user email
console.log(resp.email);
})
});
gapi.client.load('plus', 'v1', function() {
gapi.client.plus.people.get( {'userId' : 'me'} ).execute(function(resp) {
// Shows other profile information
console.log(resp);
})
});
Run Code Online (Sandbox Code Playgroud)
更多信息https://developers.google.com/+.
请注意,您不需要plus.me或userinfo.profile的范围.
| 归档时间: |
|
| 查看次数: |
8681 次 |
| 最近记录: |