Google apps script 谷歌应用程序脚本/如何设置整个段落的背景色?
我正在寻找一个Google apps script 谷歌应用程序脚本/如何设置整个段落的背景色?,google-apps-script,google-docs,http-status-code-403,Google Apps Script,Google Docs,Http Status Code 403,我正在寻找一个.gs函数,通过Google文档扩展来更改Google脚本中整个段落的背景 我一直在尝试使用外部API调用的代码段;为了让这一切顺利进行,最理想的做法是: ... var paragraph = <some way of getting the paragraph>; paragraph.setBackgroundColor('#112233'); ... 这是我在范围中的内容: https://www.googleapis.com/auth/documents.cu
.gs
函数,通过Google文档扩展来更改Google脚本中整个段落的背景
我一直在尝试使用外部API调用的代码段;为了让这一切顺利进行,最理想的做法是:
...
var paragraph = <some way of getting the paragraph>;
paragraph.setBackgroundColor('#112233');
...
这是我在范围中的内容:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/script.container.ui
https://www.googleapis.com/auth/script.external_request
下面是appsscript.json
中的一个片段:
"timeZone": "REDACTED",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Docs",
"serviceId": "docs",
"version": "v1"
}]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
我已经通过Resources->Advanced Google Services
打开了Docs API访问,通过菜单它看起来是活动的:
原始问题
看来我们有了这个答案:
但在试用时,它只是改变段落最后一行的背景,而不是像gif显示那样设置整个段落。它还使用了一个额外的呼叫;因此,我想知道是否有一种新的API可以直接设置段落背景(不是文档中指出的那样)。我得到的答案是为了工作而发布的。 我必须在
appsscript.json
中显式设置docs服务,因为某些原因,检测到它是不够的
我的appsscript.json
如下所示:
{
"timeZone": "...",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Docs",
"serviceId": "docs",
"version": "v1"
}]
},
"oauthScopes": [
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/script.external_request"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
完成后,所述解决方案对我有效。对于由此带来的不便,我深表歉意。当我测试这个脚本时,所选段落的背景发生了变化。因此,我无法复制
的情况,但在尝试时,它只是改变段落最后一行的背景,而不是像gif显示那样设置整个段落。
。我为此道歉。你能提供复制它的详细流程吗?@Tanaike非常感谢你回来并跟进答案。我现在已经更新了这个问题,我从Docs API得到了一个403,而看起来我已经设置了正确的作用域。啊!终于成功了。我不认为这与默认的vs标准有关,但您的范围是正确的-它需要在清单文件中显式设置。感谢您的回复。我很高兴你的问题解决了。顺便说一下,当作用域由清单文件管理时,不能使用脚本编辑器自动检测作用域。因此,在开发脚本时,这可能不适合这种情况。在这种情况下,当//DocumentApp.create()
作为注释行放入脚本编辑器时,https://www.googleapis.com/auth/documents
会自动检测到。这样,当您使用其他方法来使用其他作用域时,脚本编辑器可以检测到它们!为了更好地记录这种情况,您能否在回答中分享您的工作解决方案?
{
"timeZone": "...",
"dependencies": {
"enabledAdvancedServices": [{
"userSymbol": "Docs",
"serviceId": "docs",
"version": "v1"
}]
},
"oauthScopes": [
"https://www.googleapis.com/auth/documents",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/script.external_request"
],
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}