我已经在我的 Django 项目中为 Google OAuth2实现了python-social-auth库,并且能够成功地使用它登录用户。该库将access_token
收到的数据存储在 Google 的 OAuth2 流的响应中。
我的问题是:使用google-api-python-client似乎依赖于创建和授权credentials
对象,然后使用它来构建 API service
,如下所示:
...
# send user to Google consent URL, get auth_code in response
credentials = flow.step2_exchange(auth_code)
http_auth = credentials.authorize(httplib2.Http())
from apiclient.discovery import build
service = build('gmail', 'v1', http=http_auth)
# use service for API calls...
由于我从access_token
python-social-auth 提供的开始,如何创建和授权 API 客户端service
以供将来的 API 调用使用?
编辑:澄清一下,上面的代码来自谷歌提供的示例。