【问题标题】:How to Edit Google Docs title with Google Docs API?如何使用 Google Docs API 编辑 Google Docs 标题?
【发布时间】:2020-04-30 10:31:34
【问题描述】:

我尝试过 Create、batchUpdate、get from https://developers.google.com/docs/api/how-tos/overview

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

如果我有文档 ID,如何编辑文档标题? 有没有办法使用 API 编辑文档标题?

【问题讨论】:

    标签: google-docs google-docs-api


    【解决方案1】:

    我相信你的目标如下。

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

    对于这个,这个答案怎么样?

    为了修改 Google Document 的文件名,可以使用 Drive API 中的“Files:update”方法来实现。很遗憾,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);
    });
    

    【讨论】:

    • 我明白了。由于 google 文档存储在 Drive 中,因此可以尽可能使用 Drive api!我将不得不为此寻找浏览器/JS 版本。
    • @mythicalcoder 感谢您的回复。从您的回复中,我又添加了一个 Javascript 示例脚本。你能确认一下吗?
    • 谢谢。是的,看来这就是我所需要的。
    • @mythicalcoder 欢迎。谢谢你让我知道。我很高兴你的问题得到了解决。如果您的问题得到解决,请按接受按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。我认为您的问题和解决方案将对他们有用。如果找不到按钮,请随时告诉我。 stackoverflow.com/help/accepted-answer
    猜你喜欢
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多