获得令牌后,如何从Google Plus API获取电子邮件地址 [英] How can I get email address from Google Plus API once i got the token

查看:130
本文介绍了获得令牌后,如何从Google Plus API获取电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用oauth2.0进行了accessstoken。我能够获得人名,性别等,但我无法获得用户的电子邮件地址。

I have got accesstoken using oauth2.0. I am able to get the person name, gender, etc but I am not able to get the email address of the user.

任何人都可以粘贴一些示例代码或有关如何从google plus API获取电子邮件地址的任何建议吗?

Could any one please paste some sample code or any suggestions on how to get the email address from the google plus API?

推荐答案

如果用户的电子邮件地址专门授权您的应用程序查看其电子邮件地址,则可以检索用户的电子邮件地址。

You can retrieve a user's email address if they specifically authorize your application to see their email address.

设置您的范围:

https://www.googleapis.com/auth/plus.login
https://www.googleapis.com/auth/userinfo.email

JavaScript调用如下所示:

The JavaScript calls look like this:

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

更多信息 https ://developers.google.com/+

请注意,您不需要plus.me或userinfo.profile的范围。

Note that you do not need scopes for plus.me or userinfo.profile.

这篇关于获得令牌后,如何从Google Plus API获取电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆