【问题标题】:How to get email from Google Python SDK oauth2?如何从 Google Python SDK oauth2 获取电子邮件?
【发布时间】:2016-12-02 09:01:02
【问题描述】:

这似乎是一个愚蠢的问题,但我在 google sdk 文档中的任何地方都找不到它。

如何从刚刚授权我离线访问其中一个 Google API 的用户帐户获取电子邮件地址 (xxxxx@gmail.com)?

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(使用'primary' calendarId),这可能是他们的帐户电子邮件,但我不确定它必须是?如果有人更改了他们的主日历,似乎可能不会返回他们的谷歌电子邮件 ID (xxxx@gmail.com),这正是我想要的。

【问题讨论】:

    标签: python oauth-2.0 google-calendar-api


    【解决方案1】:

    在您的 OAuth 2.0 范围列表中包含 email。然后试试:

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

    【讨论】:

    • 范围网址是什么?
    • 不要使用 URL,只使用文字字符串“email”。
    • 这在文档中的什么位置?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    相关资源
    最近更新 更多