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

Gspread keep alive after update google auth2

'keep the connection with google spreadsheet alive'有几个例子 但我发现的所有内容都是基于 'old' Google 登录系统,该系统自 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.authorize(auth=credentials,http_session=headers) TypeError: authorize() 得到了一个意外的关键字参数 'auth'

您问题的迟到答案是:

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")