2016-08-16 126 views
2

我需要通過Google People API獲取聯繫人電子郵件,但無法在文檔中找到方法。目前,我正在做以下請求: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" 
    } 
    ] 
} 
+1

這是在Google Plus API下我認爲 – MatejMecka

+0

@UnknownDeveloper謝謝,我能夠通過請求'https://www.googleapis.com/plus/v1/people/me?access_token = tokenHere'獲取用戶的個人資料,但我無法找到獲取用戶聯繫人的方式,Google Plus API有可能嗎? – snowfinch27

+1

https://developers.google.com/+/web/people/ – MatejMecka

回答

3

要做到這一點,你需要使用谷歌加上API:這是我在谷歌加API文檔頁面上找到:

您可以通過使用 電子郵件範圍得到一個電子郵件地址驗證的用戶。

下面的JavaScript代碼示例演示如何:

使用Google+登錄的認證用戶,並得到有效的OAuth 2.0 訪問令牌。

使用令牌發出HTTP GET請求

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 documentation

1

指定萬一別人需要請求emailhttps://www.googleapis.com/auth/user.emails.read範圍遇到這樣的問題:解決獲取授權用戶的電子郵件地址聯繫人,OP似乎需要(不是授權用戶自己的電子郵件地址)在Why can't I retrieve emails addresses and phone numbers with Google People 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查詢(即使用connections GET端點)。該requestMask參數主要是告訴API將哪些領域:person.emailAddresses告訴它拉人民的電子郵件地址,person.emailAddresses,person.names告訴它拉他們的電子郵件地址和姓名等

相關問題