2016-12-01 81 views
0

這看起來像一個愚蠢的問題,但我實際上無法在google sdk文檔中的任何地方找到它。如何從Google Python SDK oauth2獲取電子郵件?

我怎樣從剛剛授權我的谷歌API之一離線訪問權限的用戶帳戶的電子郵件地址([email protected])?服務

import httplib2 
import datetime 

from apiclient import discovery 
from oauth2client import client 


json_credentials_as_string = "..." 

credentials = client.OAuth2Credentials.from_json(json_credentials_as_string) 
http_auth = credentials.authorize(httplib2.Http()) 
service = discovery.build('calendar', 'v3', http=http_auth) 

# ...? 

列表爲here,但沒有任何東西提到真正得到用戶的信息。

This shows how to get the primary calendar(使用「主」 calendarId),這很可能是他們的帳戶的電子郵件,但我不知道它必須是?如果有人更改了他們的主日曆,似乎可能不會返回他們的Google電子郵件ID([email protected]),這正是我想要的。

回答

2

將您的OAuth 2.0範圍列表中的email包含在您的OAuth 2.0範圍列表中。然後嘗試:

print 'Authenticated as: %s' % credentials.id_token[u'email'] 
+0

這是什麼範圍的網址? – lollercoaster

+0

不要使用URL,只需使用字符串「email」。 –

+0

這是在文檔中的位置? – lollercoaster

相關問題