python - Google 电子表格 api 不使用 OAuth2?

标签 python google-sheets google-sheets-api

我正在尝试向 Google 电子表格 API 发出授权请求,我发现的所有示例都要求用户提供电子邮件和密码。

这个问题已经通过 Google 实现的 OAuth2 协议(protocol)解决了。我已经完成了 OAuth2 流程,并且拥有有效的 access_token,我可以使用它与 Google 云端硬盘顺利交互:

access_token = get_access_token() # external function
user_agent = request.META['HTTP_USER_AGENT']
credentials = AccessTokenCredentials(access_token, user_agent)
http = httplib2.Http()
http = credentials.authorize(http)
service = build('drive', 'v2', http)
service.files().copy(fileId=k, body=dict(title="Copia")).execute() # this works!

但我无法找到使用 access_token 与电子表格 API 交互的方法。它还使用电子邮件和密码登录吗?

谢谢!

PS:顺便说一句,我正在使用 python gdata 包,如果您有好的引用,请告诉我! :)

最佳答案

所以,如果您已经有一个访问 token (也许您像我一样通过 Oauth2 协议(protocol)自己获得了它)。您可以与 Google 电子表格 API 进行交互,将 AuthSubToken 的实例传递给 SpreadsheetsClient 的方法。

from gdata.gauth import AuthSubToken
from gdata.spreadsheets.client import SpreadsheetsClient

atok = AuthSubToken(token_string=get_access_token())  # acess token via protocol
data = SpreadsheetsClient().get_worksheets(key, auth_token=atok)

关于python - Google 电子表格 api 不使用 OAuth2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13129363/

相关文章:

Laravel - Google Sheets API 为空或缺少范围

python - oauth googlesheet python共享失败

Python 共享主机

python - 文件名中的空格 python 3.4.2

python - 为什么不能这样使用star运算符? def foo(* args,此=“default”,** kwargs)

python - Spyder 集成开发环境 : How do you configure default end-of-line character?

google-apps-script - 用于发布图表的 Google 电子表格脚本

xml - Google 脚本将电子表格导出到 XML 文件

javascript - 后台验证的谷歌表格API来编辑和读取单元格的格式

.net - 谷歌CP : 403 The caller does not have permission