更新: 我在google bactch更新页上使用了api Explorer,并且能够成功更新电子表格,但是当我在代码中复制该电子表格时,仍然出现错误。 API资源管理器确实可以使用json格式。
<HttpError 400 when requesting
Invalid JSON payload received. Unknown name "value_input_option" at 'requests[0]': Cannot find field.
Invalid JSON payload received. Unknown name "data" at 'requests[0]': Cannot find field.">
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds =
ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
service = discovery.build('sheets', 'v4', credentials=creds)
client = gspread.authorize(creds)
# find workbook by name and open the first sheet
# make sure you use the right name here
sheet = client.open("forklift").sheet1
# extract and print all of the values
# list_of_hashes = sheet.get_all_records()
spreadsheet_id = '112345'
batch_update_spreadsheet_request_body = {
"requests": [
{
"valueInputOption": "RAW",
"data": [
{
"majorDimension": "ROWS",
"range": "43:48",
"values": [
["www.colossalpoint.com","colossal point llc"]
]
}
]
}
],
"includeSpreadsheetInResponse": True,
"responseIncludeGridData": True
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id,
body=batch_update_spreadsheet_request_body)
response = request.execute()