Google 幻灯片 API 报告无效请求[0].updateTableCellProperties:无效字段:table_cell_properties

Google Slides API reports Invalid requests[0].updateTableCellProperties: Invalid field: table_cell_properties

尝试解决我的应用在向 Google 幻灯片 API

发送 batchUpdate 请求后收到的错误消息
Invalid requests[19].updateTableCellProperties: Invalid field: table_cell_properties 

批次中的第 19 个请求是我唯一的 updateTableCellProperties 个请求。如果我从批处理中删除第 19 个请求,一切正常。

我 运行 在这个 batchUpdate 中没有问题的其他请求是 insertTableRowsdeleteTableRowinsertTextupdateParagraphStyleupdateTextStyleupdateTableColumnProperties。它们都在相同的 table 上工作,所以我使用相同的 objectId,但根据请求,我必须将其指定为 tableObjectId 而不是 objectId.

不确定我是否为我仅有的 updateTableCellProperties 请求生成了错误的请求,或者 Google 幻灯片 ruby gem 本身是否存在问题,我尝试仅从 Google Slides API 资源管理器发送此 updateTableCellProperties 请求,该资源管理器对请求结构进行了一些验证。所以我发送了this updateTableCellProperties batchUpdate request

{
  "requests": [
    {
      "updateTableCellProperties": {
        "objectId": "gf9d8fea71f_22_1",
        "tableRange": {
          "location": {
            "columnIndex": 0,
            "rowIndex": 1
          }
        },
        "fields": "tableCellProperties",
        "tableCellProperties": {
          "tableCellBackgroundFill": {
            "solidFill": {
              "color": {
                "themeColor": "LIGHT1"
              }
            }
          }
        }
      }
    }
  ]
}

我得到了这个错误:

{
  "error": {
    "code": 400,
    "message": "Invalid requests[0].updateTableCellProperties: Invalid field: table_cell_properties",
    "status": "INVALID_ARGUMENT"
  }
}

为什么这个 updateTableCellProperties 请求被报告为无效?我也对错误消息的输出感到困惑,因为它在 snake case 中提到了 table_cell_properties,而文档只在 camel 中提到了 tableCellProperties,而我的请求也只在 camel 中提到了 tableCellProperties案件。我只知道 ruby gems 在蛇形和骆驼形之间进行转换,但这与 API Explorer 无关。

错误Invalid field: table_cell_properties源于错误指定fields属性

documentation:

fields

At least one field must be specified. The root tableCellProperties is implied and should not be specified. A single "*" can be used as short-hand for listing every field.

所以需要修改fields

来自

"fields": "tableCellProperties"

"fields": "tableCellBackgroundFill.solidFill.color"

或到

"fields": "*"

您的请求还有第二个问题:

指定table range时,需要设置属性rowSpancolumnSpan

一个完整、正确的请求应该是:

{
  "requests": [
    {
      "updateTableCellProperties": {
        "objectId": "gf9d8fea71f_22_1",
        "tableRange": {
          "location": {
            "columnIndex": 0,
            "rowIndex": 1
          },
          "rowSpan": 1,
          "columnSpan": 1
        },
        "fields": "tableCellBackgroundFill.solidFill.color",
        "tableCellProperties": {
          "tableCellBackgroundFill": {
            "solidFill": {
              "color": {
                "themeColor": "LIGHT1"
              }
            }
          }
        }
      }
    }
  ]
}