问题描述
我正在使用Drive REST API将文件上传到Google Drive.我希望默认情况下在这些文件上启用一些默认加载项.我在在这里读到有关容器绑定脚本的信息.
I am uploading files to Google Drive using the Drive REST API. I would like to have some default add-ons enabled on those files by default.I was reading about container-bound scripts here.
但是,只有在Google Docs UI中打开文件后,才可以添加容器绑定的脚本.在上传时或以编程方式上传后,是否可以将脚本绑定到文件?
But it is only possible to add container-bound script after opening the file in Google Docs UI. Is there any way to bind a script to a file while uploading or after uploading programmatically?
推荐答案
您可以使用Apps Script API在Google文档中创建容器绑定脚本类型的项目.并且当您有一些脚本并且想要将这些脚本添加到容器绑定脚本类型的项目中时,请执行以下流程.
You can create the project of container-bound script type in Google Docs using Apps Script API. And when you have some scripts and you want to add the scripts in the project of container-bound script type, please do the following flow.
您可以使用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
将脚本导入创建的项目中.
2. Import scripts in created project
You can import the scripts in the created project using Method: projects.updateContent
.
PUT https://script.googleapis.com/v1/projects/{scriptId}/content
请求正文:
{
"files": [
{
object(File)
}
],
}
注意:
- 要使用此API,请在范围内包含
https://www.googleapis.com/auth/script.projects
. - In order to use this API, please include
https://www.googleapis.com/auth/script.projects
in the scopes. - Method: projects.create
- Method: projects.updateContent
Note :
如果这不是您想要的,对不起.
If this was not what you want, I'm sorry.
这篇关于以编程方式将容器绑定脚本添加到Google Docs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!