【问题标题】:Google Slides API reports Invalid requests[0].updateTableCellProperties: Invalid field: table_cell_propertiesGoogle Slides API 报告无效请求 [0].updateTableCellProperties:无效字段:table_cell_properties
【发布时间】:2021-11-24 03:26:42
【问题描述】:

尝试解决我的应用在向 Google Slides API 发送 batchUpdate 请求后收到的错误消息

Invalid requests[19].updateTableCellProperties: Invalid field: table_cell_properties 

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

我在这个batchUpdate 中运行的其他没有问题的请求是insertTableRows、deleteTableRow、insertText、updateParagraphStyle、updateTextStyle、updateTableColumnProperties。它们都在同一张桌子上工作,所以我使用相同的objectId,但根据请求我必须将其指定为tableObjectId 而不是objectId。

不确定我是否为我拥有的唯一一个 updateTableCellProperties 请求生成了错误请求,或者 Google 幻灯片 ruby​​ gem 本身是否存在问题,我尝试从 Google 幻灯片 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 请求被报告为无效?我也对错误消息的输出感到困惑,因为它在蛇的情况下提到了table_cell_properties,而文档只在骆驼的情况下提到了tableCellProperties,我的请求也只在骆驼的情况下提到了tableCellProperties。我只知道在蛇案例和骆驼案例之间转换的红宝石宝石,但这与 API Explorer 无关。

【问题讨论】:

    标签: google-slides-api


    【解决方案1】:

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

    见documentation:

    字段

    必须至少指定一个字段。根 tableCellProperties 是隐含的,不应指定。单个“*”可以用作列出每个字段的简写。

    所以需要修改fields

    来自

    "fields": "tableCellProperties"

    到

    "fields": "tableCellBackgroundFill.solidFill.color"

    或到

    "fields": "*"

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

    指定table range时,需要设置属性rowSpan和columnSpan。

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

    {
      "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"
                  }
                }
              }
            }
          }
        }
      ]
    }
    

    【讨论】:

    • 准确!在修复了最初的 fields 问题后,我确实收到了有关 rowSpan 和 columnSpan 的错误,这是一条很清晰且易于纠正的消息。
    猜你喜欢
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多