Gspread在更新google auth2后保持活动状态

2024-04-18 04:36:26 发布

您现在位置:Python中文网/ 问答频道 /正文

“保持与谷歌电子表格的连接”有几个例子 但我发现的都是基于“旧的”谷歌登录系统,从2015年4月起就不起作用了

使用OAuth 2.0保持与googlespreadsheet连接的正确方法是什么

我试过了

import gspread

from oauth2client.service_account import ServiceAccountCredentials

headers = gspread.httpsession.HTTPSession(headers={'Connection':'Keep-Alive'}) #Allows a persistant connection.
    scope = ['https://spreadsheets.google.com/feeds']
    credentials = ServiceAccountCredentials.from_json_keyfile_name('Apps Script Execution API.json', scope)
    c = gspread.authorize(auth=credentials,http_session=headers)

结果: c=gspread.授权(auth=credentials,http\u session=headers) TypeError:authorize()获得意外的关键字参数“auth”


Tags: fromimportauthjsonhttpsession系统oauth
1条回答
网友
1楼 · 发布于 2024-04-18 04:36:26

你的问题迟来的回答是:

import gspread
from gspread.httpsession import HTTPSession

from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds']
key_name = 'something.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_name, scope)

#gc = gspread.authorize(credentials) doesn't have a http_session kwarg
http_session = HTTPSession(headers={'Connection':'Keep-Alive'})
gc = gspread.Client(credentials, http_session)
gc.login()
ss = gc.open("Sachibondu-MasonryVaults")

相关问题 更多 >