3

我需要使用 Google People API 获取联系人电子邮件,但在文档中找不到方法。目前我正在提出以下要求:

request.get('https://people.googleapis.com/v1/people/me/connections?access_token=tokenHere',
    function (error, response, body) {
        console.log(body);
    });

并得到以下响应(例如,我只固定其中的一部分):

{
  "resourceName": "people/c1705421824339784415",
  "etag": "328OLZwdaiQ=",
  "metadata": {
    "sources": [
      {
        "type": "CONTACT",
        "id": "17aae01d0ff8b2df",
        "etag": "#328OLZwdaiQ="
      }
    ],
    "objectType": "PERSON"
  },
  "names": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "CONTACT",
          "id": "17aae01d0ff8b2df"
        }
      },
      "displayName": "testGoogleContact",
      "givenName": "testGoogleContact",
      "displayNameLastFirst": "testGoogleContact"
    }
  ]
}
4

4 回答 4

3

为此,您需要使用 Google Plus API:这是我在 Google Plus API 文档页面上找到的:

您可以使用电子邮件范围获取经过身份验证的用户的电子邮件地址。

以下 JavaScript 代码示例演示了如何:

使用 Google+ 登录对用户进行身份验证并获取有效的 OAuth 2.0 访问令牌。

使用令牌向

https://www.googleapis.com/plus/v1/people/me

REST 端点。解析响应并显示用户的电子邮件地址。

JSON 应该是这样的:

 {"kind":"plus#person","etag":"\"xw0en60W6-NurXn4VBU-CMjSPEw/mjjYoraGfq3Wi-8Nee4F3k7GYrs\"","emails":[{"value":"**EMAIL**","type":"account"}],"objectType":"person","id":"Person ID","displayName":"FULL NAME","name":{"familyName":"LAST NAME","givenName":"NAME"},"url":"https://plus.google.com/USER","image":{"url":"https://lh5.googleusercontent.com/-RTcRn6jTuoI/AAAAAAAAAAI/AAAAAAAAEpg/Y6cMxfwtbQ4/photo.jpg?sz=50","isDefault":false},"placesLived":[{"value":"CITY","primary":true}],"isPlusUser":true,"verified":false,"cover":{"layout":"banner","coverPhoto":{"url":"https://lh3.googleusercontent.com/SybH-BjYW2ft1rzayamGLg_VwW7ocgnQ5cAxH3ROEpODvyaEODpYKW55gmAxCXDUvfKggQ4=s630-fcrop64=1,00002778ffffffff","height":626,"width":940},"coverInfo":{"topImageOffset":0,"leftImageOffset":0}},"result":{"kind":"plus#person","etag":"\"xw0en60W6-NurXn4VBU-CMjSPEw/mjjYoraGfq3Wi-8Nee4F3k7GYrs\"","emails":[{"value":"**EMAIL HERE**","type":"account"}],"objectType":"person","id":"116508277095473789406","displayName":"FULL NAME","name":{"familyName":"LAST NAME","givenName":"NAME"},"url":"https://plus.google.com/USER","image":{"url":"https://lh5.googleusercontent.com/-RTcRn6jTuoI/AAAAAAAAAAI/AAAAAAAAEpg/Y6cMxfwtbQ4/photo.jpg?sz=50","isDefault":false},"placesLived":[{"value":"CITY I LIVE","primary":true}],"isPlusUser":true,"verified":false,"cover":{"layout":"banner","coverPhoto":{"url":"https://lh3.googleusercontent.com/SybH-BjYW2ft1rzayamGLg_VwW7ocgnQ5cAxH3ROEpODvyaEODpYKW55gmAxCXDUvfKggQ4=s630-fcrop64=1,00002778ffffffff","height":626,"width":940},"coverInfo":{"topImageOffset":0,"leftImageOffset":0}}}}

资料来源:Google Plus API 文档

于 2016-08-16T09:21:21.793 回答
2

万一其他人遇到这个问题:检索授权用户联系人的电子邮件地址的解决方案,OP似乎想要的(不是授权用户自己的电子邮件地址)在为什么我不能检索电子邮件地址和电话号码使用 Google 人员 API?.

说明:如果您查看https://developers.google.com/people/api/rest/v1/people.connections/list上“查询参数”下的部分,您会看到这requestMask是一个参数(记录在https ://developers.google.com/people/api/rest/v1/RequestMask)。

它说您需要requestMask在查询中包含参数,因为您正在执行people.list查询(即使用connectionsGET 端点)。该requestMask参数基本上告诉 API 要提取哪些字段:person.emailAddresses告诉它提取人们的电子邮件地址,person.emailAddresses,person.names告诉它提取他们的电子邮件地址和姓名等。

于 2017-01-13T13:42:54.960 回答
2

获取https://people.googleapis.com/v1/people/me/connections?sortOrder=FIRST_NAME_ASCENDING&fields=connections(emailAddresses%2Cnames)&key= {YOUR_API_KEY}

试试这个,它会给你电子邮件。确保您的联系人有电子邮件。

于 2017-01-24T22:55:50.433 回答
1

您可以通过向https://people.googleapis.com/v1/people/me.

如果您想要非公开电子邮件,则需要请求https://developers.google.com/people/v1/how-tos/authorizing#profile-scopes中指定的email或范围https://www.googleapis.com/auth/user.emails.read

于 2016-11-21T06:13:34.103 回答