Google 工作表 API BatchUpdate InsertRange returns "Invalid JSON payload received. Unknown name" in Python 3.6
Google Sheets API BatchUpdate InsertRange returns "Invalid JSON payload received. Unknown name" in Python 3.6
正在尝试调用 Google 个工作表 API。我阅读电子表格请求有效,但以下失败:
batch_update_spreadsheet_request_body = resource: {
'requests': ["insertRange": { 'range':{
"sheetId": 1034566956,
"startRowIndex": rowToInsert,
"endRowIndex": rowToInsert,
"startColumnIndex": 0,
"endColumnIndex": 12, },
#'shiftDimension': discovery.ROWS,
}],
"includeSpreadsheetInResponse":False,
"responseRanges": False,
"responseIncludeGridData": False, }
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=batch_update_spreadsheet_request_body)
response = request.execute()
有人告诉我语法有问题,之前找不到 JSON 名称。
Syntax Error: invalid syntax: C:\Users\evank\Google Drive\M4\ComputerScience\Create Project\Quickstart.py, line 218, pos 52 batch_update_spreadsheet_request_body = resource: {
我做错了什么?这是一个学校项目。
尝试按照 Method: spreadsheets.batchUpdate
的示例代码
"""
BEFORE RUNNING:
---------------
1. If not already done, enable the Google Sheets API
and check the quota for your project at
https://console.developers.google.com/apis/api/sheets
2. Install the Python client library for Google APIs by running
`pip install --upgrade google-api-python-client`
"""
from pprint import pprint
from googleapiclient import discovery
# TODO: Change placeholder below to generate authentication credentials. See
# https://developers.google.com/sheets/quickstart/python#step_3_set_up_the_sample
#
# Authorize using one of the following scopes:
# 'https://www.googleapis.com/auth/drive'
# 'https://www.googleapis.com/auth/spreadsheets'
credentials = None
service = discovery.build('sheets', 'v4', credentials=credentials)
# The spreadsheet to apply the updates to.
spreadsheet_id = '' # TODO: Update placeholder value.
batch_update_spreadsheet_request_body = {
# A list of updates to apply to the spreadsheet.
# Requests will be applied in the order they are specified.
# If any request is not valid, no requests will be applied.
'requests': [], # TODO: Update placeholder value.
# TODO: Add desired entries to the request body.
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=batch_update_spreadsheet_request_body)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)
如前所述,@M.Leung 检查您的第一行代码。您还可以查看 Samples,它提供了使用 Google Sheets API.
的示例代码实现
希望对您有所帮助。
正在尝试调用 Google 个工作表 API。我阅读电子表格请求有效,但以下失败:
batch_update_spreadsheet_request_body = resource: {
'requests': ["insertRange": { 'range':{
"sheetId": 1034566956,
"startRowIndex": rowToInsert,
"endRowIndex": rowToInsert,
"startColumnIndex": 0,
"endColumnIndex": 12, },
#'shiftDimension': discovery.ROWS,
}],
"includeSpreadsheetInResponse":False,
"responseRanges": False,
"responseIncludeGridData": False, }
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=batch_update_spreadsheet_request_body)
response = request.execute()
有人告诉我语法有问题,之前找不到 JSON 名称。
Syntax Error: invalid syntax: C:\Users\evank\Google Drive\M4\ComputerScience\Create Project\Quickstart.py, line 218, pos 52 batch_update_spreadsheet_request_body = resource: {
我做错了什么?这是一个学校项目。
尝试按照 Method: spreadsheets.batchUpdate
"""
BEFORE RUNNING:
---------------
1. If not already done, enable the Google Sheets API
and check the quota for your project at
https://console.developers.google.com/apis/api/sheets
2. Install the Python client library for Google APIs by running
`pip install --upgrade google-api-python-client`
"""
from pprint import pprint
from googleapiclient import discovery
# TODO: Change placeholder below to generate authentication credentials. See
# https://developers.google.com/sheets/quickstart/python#step_3_set_up_the_sample
#
# Authorize using one of the following scopes:
# 'https://www.googleapis.com/auth/drive'
# 'https://www.googleapis.com/auth/spreadsheets'
credentials = None
service = discovery.build('sheets', 'v4', credentials=credentials)
# The spreadsheet to apply the updates to.
spreadsheet_id = '' # TODO: Update placeholder value.
batch_update_spreadsheet_request_body = {
# A list of updates to apply to the spreadsheet.
# Requests will be applied in the order they are specified.
# If any request is not valid, no requests will be applied.
'requests': [], # TODO: Update placeholder value.
# TODO: Add desired entries to the request body.
}
request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=batch_update_spreadsheet_request_body)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)
如前所述,@M.Leung 检查您的第一行代码。您还可以查看 Samples,它提供了使用 Google Sheets API.
的示例代码实现希望对您有所帮助。