Google 人 API 获取联系人电子邮件
Google People API get contacts emails
我需要获取 Google 人 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"
}
]
}
要实现这一点,您需要使用 Google Plus API:这是我在 Google Plus API 文档页面上找到的内容:
You can get an email address for the authenticated user by using the
email scope.
The following JavaScript code example demonstrates how to:
Use Google+ Sign-In to authenticate the user and get a valid OAuth 2.0
access token.
Use the token to make an HTTP GET request to the
https://www.googleapis.com/plus/v1/people/me
REST endpoint. Parse the response and display the user's email
address.
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}}}}
您可以通过向 https://people.googleapis.com/v1/people/me
.
发送请求来获取 Google 人 API 的个人资料电子邮件
如果您想要非 public 电子邮件,您将需要请求 email
或 https://www.googleapis.com/auth/user.emails.read
范围,如 https://developers.google.com/people/v1/how-tos/authorizing#profile-scopes
中指定
万一其他人遇到这个问题:检索授权用户联系人电子邮件地址的解决方案,OP 似乎想要什么(不是授权用户自己的电子邮件地址)位于 .
解释:如果你在https://developers.google.com/people/api/rest/v1/people.connections/list, you'll see that requestMask
is a parameter (documented at https://developers.google.com/people/api/rest/v1/RequestMask上查看"Query Parameters"下的部分。
它说您需要在查询中包含 requestMask
参数,因为您正在执行 people.list
查询(即使用 connections
GET 端点)。 requestMask
参数基本上告诉 API 要拉取哪些字段:person.emailAddresses
告诉它拉取人们的电子邮件地址,person.emailAddresses,person.names
告诉它拉取他们的电子邮件地址和姓名,等等
获取 https://people.googleapis.com/v1/people/me/connections?sortOrder=FIRST_NAME_ASCENDING&fields=connections(emailAddresses%2Cnames)&key={YOUR_API_KEY}
试试这个,它会给你电子邮件。确保您的联系人有电子邮件。
我需要获取 Google 人 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"
}
]
}
要实现这一点,您需要使用 Google Plus API:这是我在 Google Plus API 文档页面上找到的内容:
You can get an email address for the authenticated user by using the email scope.
The following JavaScript code example demonstrates how to:
Use Google+ Sign-In to authenticate the user and get a valid OAuth 2.0 access token.
Use the token to make an HTTP GET request to the
https://www.googleapis.com/plus/v1/people/me
REST endpoint. Parse the response and display the user's email address.
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}}}}
您可以通过向 https://people.googleapis.com/v1/people/me
.
如果您想要非 public 电子邮件,您将需要请求 email
或 https://www.googleapis.com/auth/user.emails.read
范围,如 https://developers.google.com/people/v1/how-tos/authorizing#profile-scopes
万一其他人遇到这个问题:检索授权用户联系人电子邮件地址的解决方案,OP 似乎想要什么(不是授权用户自己的电子邮件地址)位于
解释:如果你在https://developers.google.com/people/api/rest/v1/people.connections/list, you'll see that requestMask
is a parameter (documented at https://developers.google.com/people/api/rest/v1/RequestMask上查看"Query Parameters"下的部分。
它说您需要在查询中包含 requestMask
参数,因为您正在执行 people.list
查询(即使用 connections
GET 端点)。 requestMask
参数基本上告诉 API 要拉取哪些字段:person.emailAddresses
告诉它拉取人们的电子邮件地址,person.emailAddresses,person.names
告诉它拉取他们的电子邮件地址和姓名,等等
获取 https://people.googleapis.com/v1/people/me/connections?sortOrder=FIRST_NAME_ASCENDING&fields=connections(emailAddresses%2Cnames)&key={YOUR_API_KEY}
试试这个,它会给你电子邮件。确保您的联系人有电子邮件。