4

我正在使用 Drive REST API 将文件上传到 Google Drive。我希望默认情况下在这些文件上启用一些默认加载项。我在这里阅读了有关容器绑定脚本的信息。

但只能在 Google Docs UI 中打开文件后添加容器绑定脚本。有没有办法在上传时或以编程方式上传后将脚本绑定到文件?

4

1 回答 1

9

您可以使用 Apps Script API 在 Google Docs 中创建容器绑定脚本类型的项目。并且当你有一些脚本并且你想在容器绑定脚本类型的项目中添加脚本时,请执行以下流程。

1. 在 Google Docs 中创建新项目

您可以使用Method: projects.create.

端点:

POST https://script.googleapis.com/v1/projects

请求正文:

{
  "title": string, // project name
  "parentId": string, // file ID of Google Docs
}

2.在创建的项目中导入脚本

您可以使用Method: projects.updateContent.

端点:

PUT https://script.googleapis.com/v1/projects/{scriptId}/content

请求正文:

{
  "files": [
    {
      object(File)
    }
  ],
}

笔记 :

  • 要使用此 API,请包含https://www.googleapis.com/auth/script.projects在范围内。

参考 :

如果这不是你想要的,我很抱歉。

于 2018-04-26T11:13:23.530 回答