2016-07-25 47 views
0

如果我打开某人的Google Plus配置文件页面,我会看到Google Plus上共享的联系信息和信息。我正在寻找有关Google API的类似信息。我试图通过电子邮件和谷歌加配置文件ID获取用户联系人列表,就这些了。正在获取Google Plus配置文件网址和电子邮件

在这里,我可以通过Google Plus个人资料网址获取用户连接,但没有电子邮件或电话号码。

https://people.googleapis.com/v1/people/me/connections

在这里,我可以获取电子邮件和电话号码(OAuth2用户)的人接触 - 没有谷歌加的个人资料网址或ID

https://www.google.com/m8/feeds/contacts/{GOOGLE_ACCOUNT_NAME}%40gmail.com/full?alt=json

但我不知道如何将这种结合两个输出,以获得Google Plus个人资料网址和联系信息。

回答

1

你是正确的JSON数组给出。要检索用户的配置文件信息,请使用people.get API method。要获取当前授权用户的配置文件信息,请使用值为meuserId

gapi.client.load('plus','v1', function(){ 
var request = gapi.client.plus.people.get({ 
'userId': 'me' 
}); 
request.execute(function(resp) { 
console.log('Retrieved profile for:' + resp.displayName); 
}); 
}); 

注意,此方法要求身份验证使用已授予OAuth scopehttps://www.googleapis.com/auth/plus.login or https://www.googleapis.com/auth/plus.me的令牌。

Plus.People.List listPeople = plus.people().list(
"me", "visible"); 
listPeople.setMaxResults(5L); 

PeopleFeed peopleFeed = listPeople.execute(); 
List<Person> people = peopleFeed.getItems(); 

// Loop through until we arrive at an empty page 
while (people != null) { 
for (Person person : people) { 
System.out.println(person.getDisplayName()); 
} 

// We will know we are on the last page when the next page token is 
// null. 
// If this is the case, break. 
if (peopleFeed.getNextPageToken() == null) { 
break; 
} 

// Prepare the next page of results 
listPeople.setPageToken(peopleFeed.getNextPageToken()); 

// Execute and process the next page request 
peopleFeed = listPeople.execute(); 
people = peopleFeed.getItems(); 
} 

这里有一个相关的SO票,其讨论如何从Google+中的Oauth获取用户电子邮件:How to get user email from google plus oauth

+0

我想要我的朋友的电子邮件,而不仅仅是授权用户。 –

0

您可以使用Google Api来获取用户配置文件。为此

  1. google api console中创建项目。配置证书客户端ID,客户端密钥。添加你的重定向uri。

  2. 从范围https://www.googleapis.com/auth/plus.mehttps://www.googleapis.com/auth/plus.login项目授权使用OAuth2.0的用户。

  3. 授权后检索响应码。使用POST方法到令牌端点url

  4. 从gooogle plus中检索access_token,refresh_token,id_token等。

  5. 通过使用access_token。请将GET方法调用到URL“https://www.googleapis.com/plus/v1/people/me/?access_token='{YOUR_ACCESS_TOKEN}'”。

您将通过包含授权的用户配置文件的详细信息,如电子邮件,姓名,身份证等

+0

我希望我的朋友们的电子邮件,而不仅仅是授权用户。 –

相关问题