简体   繁体   English

通过幻灯片 API 批量更新在 Google 幻灯片中设置主题 Colors 时遇到问题

[英]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:在您的情况下,请切换DARK2LIGHT1的位置,因为它没有遵循正确的顺序:

  • DARK1黑暗1
  • LIGHT1灯光1
  • DARK2黑暗2
  • LIGHT2灯2
  • ACCENT1口音1
  • ... ...
  • ACCENT6口音6
  • HYPERLINK超链接
  • FOLLOWED_HYPERLINK FOLLOWED_HYPERLINK
  • TEXT1文本1
  • BACKGROUND1背景1
  • TEXT2文本2
  • BACKGROUND2背景2

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.

相关问题 使用谷歌幻灯片 API 更新谷歌幻灯片中对象的文本 - Update text of an object in google slides using google slides API 如何通过 API 呈现 Google 幻灯片演示文稿并控制/移动幻灯片? - How to render a Google Slides presentation via API and control / move slides? 如何通过 API 呈现 Google 幻灯片演示文稿 - How to render a Google Slides presentation via API Google Suite - Apps 脚本 - 通过 API 将幻灯片下载为 PNG 文件 - Google Suite - Apps Script - Download Slides as PNG files via API 无法通过Google Slides API将表格图表插入演示文稿 - Cannot insert Sheets chart to presentation via Google Slides API 有没有办法使用脚本在 Google 幻灯片中设置主题 colors(ACCENT1、ACCENT2 等)? - Is there a way to use a script to set theme colors (ACCENT1, ACCENT2 etc) in Google Slides? Google Slides API舍入问题? - Google Slides API Rounding Issues? 是否有一种已知的方法可以在 Google Slides API 中更新页面设置大小? - Is there a known way to update the page setup size In the Google Slides API? 使用 Google Slides API 是否可以在同一批次更新期间在所有或任何剩余请求中使用来自一个请求的响应 - Using Google Slides API is it possible to use the response from one request in all or any of the remaining requests during the same batch Update 使用 Google Apps Script 和 Slides API 删除 Google Slides 中的笔记 - Remove notes in Google Slides using Google Apps Script and Slides API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM