Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Sheets API BatchUpdate InsertRange返回;接收到无效的JSON负载。“未知名称”;在Python 3.6中_Python_Json_Syntax_Google Api_Google Sheets Api - Fatal编程技术网

Google Sheets API BatchUpdate InsertRange返回;接收到无效的JSON负载。“未知名称”;在Python 3.6中

Google Sheets API BatchUpdate InsertRange返回;接收到无效的JSON负载。“未知名称”;在Python 3.6中,python,json,syntax,google-api,google-sheets-api,Python,Json,Syntax,Google Api,Google Sheets Api,正在尝试调用Google Sheets API。我对电子表格的阅读要求工作,但以下失败: batch_update_spreadsheet_request_body = resource: { 'requests': ["insertRange": { 'range':{ "sheetId": 1034566956,

正在尝试调用Google Sheets 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: {

我做错了什么?这是一个学校项目。

试着按照

如上所述,@M.Leung检查您的第一行代码。您还可以检查,这提供了使用GoogleSheetsAPI的示例代码实现


希望这有帮助。

您发布的第一行是
resource
您的请求正文的密钥吗?应该是{'resource':xxx}或者没有
资源
,只要{'request':xxx}也应该是
[{“insertRange:something}]
"""
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)