我是 googleapiclient 的新手。现在,我想出了使用 credentials.json 和 token.pickle 将数据从 GSheet 获取到 S3 的代码。
scope = ['https://www.googleapis.com/auth/spreadsheets.readonly']
credentials = get_google_token(scope=scope, token_file=token_file, cred_file=cred_file)
service = build('sheets', 'v4', credentials=credentials, cache_discovery=False)
range_name = sheet_title + '!' + sheet_range_name
# Call the Sheets API
sheet = service.spreadsheets()
result = sheet.values().get(spreadsheetId=spreadsheetId,
range=range_name
).execute()
当我尝试更新记录(反之亦然)时,我无法授权 Http 并且我不知道如何处理“使用 Google API 客户端编写 Google Sheet”。
scope = ['https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
credentials = get_google_token(scope=scope, token_file=token_file, cred_file=cred_file)
print(credentials)
service = build('sheets', 'v4', credentials=credentials)
print(service)
values = {'values':[['Hello World',],]}
range_name = sheet_title + '!' + sheet_range_name
# Call the Sheets API to Update the Value
result = service.spreadsheets().values().update(spreadsheetId=spreadsheetId,range=sheet_range_name,valueInputOption='RAW',body=values).execute()