我有gspread和oauth2client的最新版本。对于较旧的代码,我的代码可以运行,但对于最近的代码,则出现此错误:
HttpAccessTokenRefreshError: invalid_grant: Invalid JWT Signature.
我已经尝试过此Gspread to access google spreadsheet: HttpAccessTokenRefreshError, invalid JWT,但是 SignedJwtAssertionCredentials 已弃用,并且出现错误。
以下是旧版本的工作代码(可以使用凭据):
def clientSheet():
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
client = gspread.authorize(creds)
return client
def refreshSheet(sheet):
return clientSheet().open(sheet).sheet1
我也曾尝试添加googleapis的驱动器身份验证,如此处https://gspread.readthedocs.io/en/latest/oauth2.html所示