0

我正在创建一个应用程序来登录 Google+ 并获取朋友的电子邮件。我成功验证并取回令牌,但是当我获取朋友列表时,任何单个朋友的用户类都有 emails=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..

有什么帮助吗?

4

3 回答 3

6

The Google+ API only returns public information. So even if you are permitted to see a person's email address, it does not necessarily mean that the information is public and that it will be returned.

Furthermore, the documentation at https://developers.google.com/+/api/latest/people/list only guarantees that the list of people returned will contain the person's

  • id
  • displayName
  • image
  • url

and that to get other information about the person, you will need to do a people.get against that ID. But, again, note that you may still not get their email if that information isn't public.

于 2013-10-23T10:49:29.483 回答
1

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

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

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

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

于 2013-10-23T18:03:48.580 回答
-1

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

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

于 2013-10-23T09:42:16.927 回答