gpt4 book ai didi

google-drive-api - 存储来自 Google OAuth 2.0 的访问 token 以从应用程序帐户访问驱动器数据

转载 作者:行者123 更新时间:2023-12-04 10:40:15 24 4
gpt4 key购买 nike

我能够执行 quickstart.py对于使用 python 的 Google Drive。但是我们如何存储 token 并再次使用它 - 再次为同一用户而不提示用户。在 Google 驱动器上发送文件请求时,我可以使用访问 token 映射用户,这是他们的某种方式。

最佳答案

有很多不同的Storage google-api-python-client 提供的类型, some其中是well documented .

一些例子:

oauth2client.file.Storage:

from oauth2client.file import Storage
...
storage = Storage('a_credentials_file')
storage.put(credentials)
...
credentials = storage.get()

oauth2client.keyring_storage.Storage:
from oauth2client.keyring_storage import Storage
...
storage = Storage('application name', 'user name')
storage.put(credentials)
...
credentials = storage.get()

oauth2client.appengine.StorageByKeyName:
from oauth2client.keyring_storage import StorageByKeyName
from oauth2client.keyring_storage import CredentialsNDBModel
...
storage = StorageByKeyName(CredentialsNDBModel, some_user_id, 'credentials')
storage.put(credentials)
...
credentials = storage.get()

oauth2client.django_orm.Storage:
from django.contrib.auth.models import User
from oauth2client.django_orm import Storage
from your_project.your_app.models import CredentialsModel
...
user = # A User object usually obtained from request.
storage = Storage(CredentialsModel, 'id', user, 'credential')
credential = storage.get()
...
storage.put(credential)

关于google-drive-api - 存储来自 Google OAuth 2.0 的访问 token 以从应用程序帐户访问驱动器数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15493062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com