[英]Having trouble setting Theme Colors in Google Slides via the Slides API batch update
I am creating a new presentation and would like to set the theme colors.我正在创建一个新的演示文稿并想设置主题 colors。 When I run the following code, I get the error:
当我运行以下代码时,出现错误:
"GoogleJsonResponseException: API call to slides.presentations.batchUpdate failed with error: Invalid requests[0].updatePageProperties: Color scheme cannot have duplicate theme color types"
“GoogleJsonResponseException:API 调用 slides.presentations.batchUpdate 失败并出现错误:无效请求 [0].updatePageProperties:配色方案不能有重复的主题颜色类型”
Below is my code...下面是我的代码...
var presentation = Slides.Presentations.create({
title: 'colorSchemeTest'
});
var master = presentation.masters[0];
var requests = [{
updatePageProperties: {
objectId: master.objectId,
pageProperties: {
colorScheme: COLOR_SCHEME
},
fields: "colorScheme.colors"
}
}];
Slides.Presentations.batchUpdate( { requests: requests }, presentation.presentationId );
...and here is the enum COLOR_SCHEME ...这是枚举 COLOR_SCHEME
var COLOR_SCHEME = {
colors: [
{//Black
type: "DARK1",
color: {
red: 0,
green: 0,
blue: 0
}
},
{//Dark Gray
type: "DARK2",
color: {
red: .263,
green: .263,
blue: .263
}
},
{//White
type: "LIGHT1",
color: {
red: 1,
green: 1,
blue: 1
}
},
{//Whisper Gray
type: "LIGHT2",
color: {
red: .953,
green: .953,
blue: .953
}
},
{// Blue
type: "ACCENT1",
color: {
red: .259,
green: .522,
blue: .957
}
},
{// Green
type: "ACCENT2",
color: {
red: .204,
green: .659,
blue: .325
}
},
{// Yellow
type: "ACCENT3",
color: {
red: .984,
green: .737,
blue: .020
}
},
{// Red
type: "ACCENT4",
color: {
red: .918,
green: .263,
blue: .208
}
},
{//Purple
type: "ACCENT5",
color: {
red: .612,
green: .153,
blue: .690
}
},
{//Gray
type: "ACCENT6",
color: {
red: .800,
green: .800,
blue: .800
}
},
{//Primary Gray
type: "TEXT1",
color: {
red: .400,
green: .400,
blue: .400
}
},
{//Another Gray
type: "TEXT2",
color: {
red: .600,
green: .600,
blue: .600
}
}
]
}
This is my first time addressing a Google Slides API problem, so the accuracy of my reasoning may be a bit off.这是我第一次解决 Google 幻灯片 API 问题,所以我推理的准确性可能有点偏差。
I fixed the error.我修复了错误。 I noticed that although you have listed 12 colors to complete the ColorScheme array (as per this documentation https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/other#themecolortype ) you are required to follow the ThemeColorType order as outlined in that documentation.
我注意到虽然您列出了 12 colors 来完成 ColorScheme 数组(根据本文档https://developers.google.com/slides/api/reference/rest/v1/presentations.pages/other#themecolortype )遵循该文档中概述的 ThemeColorType 顺序。 In your case, switch positions for
DARK2
& LIGHT1
as it does not follow the right order:在您的情况下,请切换
DARK2
和LIGHT1
的位置,因为它没有遵循正确的顺序:
This will correct the Color scheme cannot have duplicate theme color types
error message.这将纠正
Color scheme cannot have duplicate theme color types
错误消息。
In addition to that, it seems that you are required to enter a HYPERLINK
& FOLLOWED_HYPERLINK
ThemeColorPairs to complete the theme.除此之外,您似乎需要输入
HYPERLINK
& FOLLOWED_HYPERLINK
ThemeColorPairs 才能完成主题。
You need to add this to the enum COLOR_SCHEME (always following the order, additional ThemeColorPairs are optional):您需要将此添加到枚举 COLOR_SCHEME(始终遵循顺序,附加 ThemeColorPairs 是可选的):
{
"type": "HYPERLINK",
"color": {
"red": 0.6,
"green": 0.6,
"blue": 0.6
}
},
{
"type": "FOLLOWED_HYPERLINK",
"color": {
"red": 0.9,
"green": 0.9,
"blue": 0.9
}
}
Not adding these 2 ThemeColorPairs will result in the following error: Please provide the appropriate 12 theme colors to complete the color scheme
不添加这2个ThemeColorPairs会导致如下错误:
Please provide the appropriate 12 theme colors to complete the color scheme
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.