Google 幻灯片 API 脚本 updateShapeProperties 自动调整

Google Slide API script updateShapeProperties autofit

收到错误“GoogleJsonResponseException:API 调用 slides.presentations.batchUpdate 失败,出现错误:请求无效 [3].updateShapeProperties:字段无效:autofit_type”

但我认为我的代码是正确的:

'updateShapeProperties': {
  'objectId': pageElementId,
    'fields': 'autofitType',
    'shapeProperties': {
    'autofit': {
      'autofitType':'SHAPE_AUTOFIT'
    }
  }
}

非常感谢任何帮助 干杯 格雷格

如错误消息所述,您使用的字段无效。

您可以参考 here 以了解可用于替换您的 'autofitType' 字段的可用字段。

我以为错误信息是说fields的值不正确。在你的脚本中,修改如下。

发件人:

'fields': 'autofitType',

收件人:

'fields': 'autofit.autofitType',

注:

  • 但是,在现阶段,好像autofitType的值只能用NONE。所以,当SHAPE_AUTOFITTEXT_AUTOFIT用于autofitType时,就会出现Autofit types other than NONE are not supported.的错误。请注意这一点。
    • 关于这个,问题跟踪器中似乎没有将其报告为未来的请求。那么将其报告为未来的请求怎么样? Ref
  • 测试以上修改时,请将'autofitType':'SHAPE_AUTOFIT'修改为'autofitType':'NONE'。这样,请求就没有错误了。

参考:

针对 Jason E. 的回复,请参阅记录的 AutofitType 枚举 1