Python3 Google电子表格API批处理更新Json格式 [英] Python3 google spreadsheet api batchUpdate Json formatting

查看:112
本文介绍了Python3 Google电子表格API批处理更新Json格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用google电子表格api batchUpdate来更新具有相同请求的不同值.

I want to use google spreadsheet api batchUpdate to update different values with the same request.

在文档示例中,他们使用字典存储Json请求,但我需要多次设置相同的属性(insertDimension). Google期望的请求在这里

In the documentation examples they use a dict to store the Json request but I need to set the same attribute (insertDimension) multiple times. Here Google expected request

{
  "requests": [
    {
      "insertDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "COLUMNS",
          "startIndex": 2,
          "endIndex": 4
        },
        "inheritBefore": true
      }
    },
    {
      "insertDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "ROWS",
          "startIndex": 0,
          "endIndex": 3
        },
        "inheritBefore": false
      }
    },
  ],
}

我尝试使用json.dumps

I tried using json.dumps

mydata = json.dumps('''

mydata = json.dumps('''

请求":[{{"updateDimensionProperties":{"range":{"sheetId":0,"dimension":"ROWS","startIndex":0 "endIndex":50 }, 特性": { "pixelSize":10 }, "fields":"pixelSize" } } }]''')

"requests": [{{"updateDimensionProperties": {"range": {"sheetId": 0,"dimension": "ROWS","startIndex": 0 "endIndex": 50 }, "properties": { "pixelSize": 10 }, "fields": "pixelSize" } } } ] ''')

但我收到此错误消息 接收到无效的JSON有效载荷.名称未知"::根元素必须是一条消息."

but I receive this error message "Invalid JSON payload received. Unknown name "": Root element must be a message."

推荐答案

您的请求无效,因为它从不说这是哪种请求:insertDimension请求.正确的格式是

Your request is invalid because it never says what kind of request it is: the insertDimension request. The correct form is

{
"requests": [
  {
  "insertDimension": { 
    # required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
  }
  },
  {
  "insertDimension": { 
    # required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
  }
  }]
}

顺便说一句,字段之一是inheritFromBefore,而不是inheritBefore

By the way, one of the fields is inheritFromBefore, not inheritBefore

这篇关于Python3 Google电子表格API批处理更新Json格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆