代码之家  ›  专栏  ›  技术社区  ›  mythicalcoder

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

  •  0
  • mythicalcoder  · 技术社区  · 4 年前

    我试过创建、批量更新、获取 https://developers.google.com/docs/api/how-tos/overview .

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

    如果我有文档id,如何编辑文档标题? 是否有任何方法可以使用API编辑文档标题?

    0 回复  |  直到 4 年前
        1
  •  4
  •   Tanaike    4 年前

    我相信你的目标如下。

    • 您想修改Google文档的标题。
      • 也就是说,你想修改谷歌文档的文件名。

    对此,这个答案如何?

    为了修改Google文档的文件名,您可以使用Drive API中的“文件:更新”方法来实现这一点。遗憾的是,Google文档API无法用于修改Google文档的文件名。

    端点:

    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 用于修改标题。作为示例脚本,我向您展示了Javascript的Files:update方法的示例脚本,如下所示。请使用来自的授权脚本 the quickstart .

    示例脚本:

    gapi.client.drive.files.update({
      fileId: fileId,
      resource: {name: "updated title"},
    }).then((response) => {
      console.log(response);
    });