python-3.x - 从身份验证代码在 token.pickle 中创建和存储 Google 凭据
问题描述
我正在编写一个程序,它使用本地token.pickle
文件来访问用户的谷歌日历。
它在服务器上运行,我希望用户能够通过 Web 界面登录,然后服务器创建并存储 token.pickle 文件,该文件是根据页面发送回服务器的身份验证代码创建的。
我现在的位置是我的 Python 后端接收到授权代码,但我不知道如何从中创建 token.pickle 文件......我知道我需要交换用户凭据的代码,我可能需要使用以下代码段:
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
和
# Set path to the Web application client_secret_*.json file you downloaded from the
# Google API Console: https://console.developers.google.com/apis/credentials
CLIENT_SECRET_FILE = '/path/to/client_secret.json'
# Exchange auth code for access token, refresh token, and ID token
credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code)
谢谢,我将不胜感激任何帮助。
编辑:
好的,所以我想保存某种从访问令牌中获取凭据或凭据本身的方法,这样我就可以从以下位置访问它们:
service = build('calendar', 'v3', credentials=creds)
有人可以澄清或给我一个方法吗?
解决方案
推荐阅读
- spring - 使用线程池的 JMS 侦听器
- c# - 如何定位记录类的属性?
- c++ - 为什么 glsl '#version' 定义给我一个错误?
- ios - 在 iOS 上使用 AVPlayer 连接蓝牙时音频失真
- c# - 使用 EF6 检查派生实体类型的属性?
- azure-data-factory - ADF v2 中的 Web 活动未发送内容类型标头
- c - 如果 C 比较两个双精度数错误,我该怎么办?
- telegram - 电报如何确定用户语言
- opencv3.0 - 对属于同一对象的一组点进行卡尔曼滤波器?
- google-cloud-bigtable - 使用 bigtable cbt 中的列值进行搜索