How to get Email of friend using google+ api?

2019-03-04 22:37发布

Im creating an application to login in Google+ and get friends emails. Im authenticating succesfully and get token back , but when i fetch friends list , the user class of any single friends has emails=null...

here is the code (After already signed in and get authenticator class):

// 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..

any help?

3条回答
何必那么认真
2楼-- · 2019-03-04 22:56

You could also use the Contacts v3 API to get friend's email addresses. You can cross map this to Google+ contacts by looking at the gContact:website element for the contact that comes back in the XML response:

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

In that element's href attribute, 1234567890 is the person identifier that would match the id field of the relevant person resource from people.list of the Google+ API.

Note that the profile link is not guaranteed to come back for a contact entry. This occurs when the contact has not been linked to a Google+ profile.

查看更多
别忘想泡老子
3楼-- · 2019-03-04 23:20

My first guess would be that it's a rights management issue. I remember when I asked for my Google API key, I had to mention what information I want to get.

Could you check your API key settings in the Google Developer network and see if you need to enable it there?

查看更多
混吃等死
4楼-- · 2019-03-04 23:21

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.

查看更多
登录 后发表回答