简体   繁体   English

我可以使用此逻辑来获取Google帐户的电子邮件地址(使用Google+ API(人))

[英]May I use this logic to get the Google Account email address (using Google+ API (People) )

when I use 「 https://www.googleapis.com/plus/v1/people/ {userId}」to get the json of people profile, I use the code below to get user's google account email(.NET) but is there any guarantee that the user's google account is the first one of emails[] array? 当我使用“ https://www.googleapis.com/plus/v1/people/ {userId}”来获取人物个人资料的json时,我使用下面的代码来获取用户的google帐户电子邮件(.NET),但是是否可以保证用户的Google帐户是emails []数组的第一个? I doubt if this is the right way to get a user's email. 我怀疑这是否是获取用户电子邮件的正确方法。

        if (json.emails != null)
        {
            if (json.emails.Count != 0)
            {
                if (json.emails[0].type == "account")
                email = json.emails[0].value;
            }
        }

First of all I would use https://www.googleapis.com/plus/v1/people/me as its the current authenticated user you are after. 首先,我将使用https://www.googleapis.com/plus/v1/people/me作为您正在https://www.googleapis.com/plus/v1/people/me的当前经过身份验证的用户。

If you read the documentation found at: People 如果您阅读位于以下位置的文档: 人员

Emails is a list with value and the type.  Type = account is what you are after.

The type of address. 地址类型。 Possible values include, but are not limited to, the following values: 可能的值包括但不限于以下值:

  • "account" - Google account email address. “帐户”-Google帐户的电子邮件地址。
  • "home" - Home email address. “家庭”-家庭电子邮件地址。
  • "work" - Work email address. “工作”-工作电子邮件地址。
  • "other" - Other. “其他”-其他。

The list may contain more the one email address, but just scan though them looking for the one that is set to type = account. 该列表可能包含更多的一个电子邮件地址,但是只要扫描它们以查找设置为= account的那个电子邮件地址即可。

Note: Scroll to the bottom of this page you can play with the response: https://developers.google.com/+/api/latest/people/get 注意:滚动到此页面底部,您可以使用以下响应: https : //developers.google.com/+/api/latest/people/get

(Remember to authenticate it in the top of the "Try it!" form, also in the userId field just type me) (请记住在“尝试它!”表单的顶部进行身份验证,也请在userId字段中键入我)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Google+ API在Google+中将人添加到Circle? - How to add people to Circle in Google+ using Google+ API? 如何使用google+ api获取朋友的电子邮件? - How to get Email of friend using google+ api? Google+ API人员列表未返回任何内容 - Google+ API People List return nothing 如何使用谷歌获取用户的 email 地址 Oauth api - How to get user's email address using google Oauth api 当用户使用其Google+帐户唱歌时,我可以获取所有数据,但不能发送电子邮件。 email = null和verify_email = false - When User sing in with their Google+ account, I can get all data, but only can't email. email=null and verified_email=false 当我请求谷歌人员 api 时,没有最后修改的时间戳 - Get no last modified timestamp when I request google people api 如何在ASP.NET 4.5 C#中通过OWIN访问Google+用户的电子邮件和图片地址? - How can I access Google+ user's email and pictures address through OWIN in ASP.NET 4.5 C#? 使用服务帐户凭据通过 Google People API 访问 Gmail 联系人始终返回 null - Accessing Gmail contacts via the Google People API using service account credentials always returning null Google+ API:如何在每次启动应用时使用RefreshTokens来避免请求访问权限? - Google+ API: How can I use RefreshTokens to avoid requesting access every time my app launches? Google+ SignIn API和电子邮件 - Google+ SignIn API and emails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM