gpt4 book ai didi

python - 如何正确连接Google Spreadsheets API?

转载 作者:行者123 更新时间:2023-11-30 21:58:32 25 4
gpt4 key购买 nike

我想使用 Python 连接到 Google Spreadsheets API。

所以我这样做:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope=['https://www.googleapis.com/auth/spreadsheets',
'https://wwww.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('cred.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open('datatest').Sheet1

print(wks.get_all_records)

但我收到此错误

HttpAccessTokenRefreshError: invalid_scope: https://www.googleapis.com/auth/spreadsheets is not a valid audience string.

如何使用 Google-auth 而不是 gspread 来处理此数据?

最佳答案

你输入4w!!!

X'https://wwww.googleapis.com/auth/drive '

O'https://www.googleapis.com/auth/drive '

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('CredentialsFile.json', scope)
ss_app = gspread.authorize(credentials=credentials) # make sure your Google Sheets API is enabled
sht = ss_app.open('sheet_name_xxxx') # In your spreadsheet, click the Share button and paste the client email as same as CredentialsFile.json.client_email, and make sure your Google Drive API is enabled
wks = sht.worksheet('worksheet_name_xxxx')
print(wks.acell('A1').value)

希望对你有帮助。

关于python - 如何正确连接Google Spreadsheets API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54896118/

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