如何使用谷歌+ api获取朋友的电子邮件

本文关键字:朋友 电子邮件 获取 api 何使用 谷歌 | 更新日期: 2023-09-27 18:36:35

我正在创建一个应用程序来登录Google+并接收朋友的电子邮件。我成功进行身份验证并取回令牌,但是当我获取朋友列表时,任何单个朋友的用户类都有电子邮件=null...

这是代码(已经登录并获取身份验证器类之后):

// Generated libraries for Google APIs
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Services;
using Google.Apis.Util;
using Google.Apis.Plus.v1;
using Google.Apis.Plus.v1.Data;
// For OAuth2
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
//....code for authentication skipped ....

//...callback from json (authentication success)
PlusService ps = new PlusService(new BaseClientService.Initializer()
{
  Authenticator = authenticator
});
PeopleFeed peopleFeed = ps.People.List("me", PeopleResource.CollectionEnum.Visible).Fetch();
//After that when i inspect peopleFeed[0].Emails <--- this is null..

有什么帮助吗?

如何使用谷歌+ api获取朋友的电子邮件

Google+ API 仅返回公共信息。因此,即使您被允许查看某人的电子邮件地址,也不一定意味着该信息是公开的并且将被退回。

此外,https://developers.google.com/+/api/latest/people/list 的文件仅保证返回的人员名单将包含该人的

  • 编号
  • 显示名称
  • 图像
  • 网址

并且要获取有关此人的其他信息,您需要对该ID进行people.get。但是,再次请注意,如果该信息不公开,您可能仍然无法收到他们的电子邮件。

您还可以使用联系人 v3 API 获取朋友的电子邮件地址。您可以通过查看 XML 响应中返回的联系人的gContact:website元素,将其交叉映射到 Google+ 联系人:

<gContact:website href='http://www.google.com/profiles/1234567890' rel='profile'/>

在该元素的 href 属性中,1234567890 是与 Google+ API 的 people.list 中的相关人员资源的id字段匹配的人员标识符。

请注意,不保证个人资料链接会返回联系人条目。当联系人尚未关联到 Google+ 个人资料时,就会发生这种情况。

我的第一个猜测是这是一个权限管理问题。我记得当我要求我的谷歌API密钥时,我不得不提到我想得到什么信息。

您能否在Google开发者网络中检查您的API密钥设置,看看是否需要在那里启用它?