如何使用Google Docs API编辑Google Docs标题?

问题描述 投票:0回答:1

我尝试过创建,batchUpdate,从https://developers.google.com/docs/api/how-tos/overview获取。

即使在batchUpdate中也看不到编辑title的选项。我已经使用它来编辑文档的内容-插入/删除,但没有标题。

鉴于我具有文档ID,如何编辑文档标题?是否可以使用API​​编辑文档标题?

google-docs google-docs-api
1个回答
2
投票

我相信您的目标如下。

  • 您要修改Google文档的标题。
    • 即,您想修改Google文档的文件名。

为此,这个答案如何?

为了修改Google文档的文件名,您可以使用Drive API中的“文件:更新”方法来实现。不幸的是,Google Docs API无法用于修改Google Document的文件名。

端点:

PATCH https://www.googleapis.com/drive/v3/files/fileId

样品请求正文:

{"name":"updated title"}

样品卷曲:

curl --request PATCH \
  'https://www.googleapis.com/drive/v3/files/{documentId}' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{"name":"updated title"}' \
  --compressed

参考:

添加:

想要使用浏览器进行请求时,可以使用this quickstart进行授权,并使用Files: update进行标题修改。作为一个示例脚本,我向您展示了Files:update for Javascript方法的示例脚本,如下所示。请使用the quickstart中的授权脚本。

示例脚本:

gapi.client.drive.files.update({
  fileId: fileId,
  resource: {name: "updated title"},
}).then((response) => {
  console.log(response);
});
© www.soinside.com 2019 - 2024. All rights reserved.