正在获取 Google Plus 个人资料 url 和电子邮件

Fetching Google Plus profile url and email

如果我打开某人的 Google Plus 个人资料页面,我会看到联系信息和在 Google Plus 上共享的信息。我在 Google API 上寻找类似的信息。我正在尝试使用电子邮件和 google 加上个人资料 ID 来获取用户的联系人列表,仅此而已。

在这里,我可以获取具有 Google Plus 配置文件 url 但没有电子邮件或 phone 号码的用户连接。

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

在这里,我可以通过电子邮件和 phone 号码 (OAuth2) 获取个人联系人 - 没有 Google Plus 个人资料 url 也没有 ID

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

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

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

  1. google api console 中创建项目。配置凭据客户端 ID、客户端密码。添加您的重定向 uri。

  2. 使用范围为 https://www.googleapis.com/auth/plus.me , https://www.googleapis.com/auth/plus.login.

  3. 的项目中的 OAuth2.0 授权用户
  4. 在 authorization.Give POST 方法后检索响应代码到令牌端点 url

  5. 从 gooogle plus 检索 access_token、refresh_token、id_token 等。

  6. 通过使用access_token。对 url "https://www.googleapis.com/plus/v1/people/me/?access_token='{YOUR_ACCESS_TOKEN}'".

  7. 调用 GET 方法

您将得到一个 json 数组,其中包含授权用户个人资料的详细信息,例如电子邮件、姓名、ID 等。

你是对的。要检索用户的配置文件信息,请使用 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 scope https://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