gpt4 book ai didi

javascript - 错误 : Invalid value at 'requests[0]' (oneof), 一个字段 'kind' 已经设置。无法设置 'createShape'

转载 作者:行者123 更新时间:2023-11-30 20:03:38 25 4
gpt4 key购买 nike

我正在使用 google slides API 并尝试根据用户输入的文本制作幻灯片。这是我的文本创建功能,

var num = 1;
function createSlide(auth) {
//AUTHENTICATION
const slides = google.slides({version: 'v1', auth});

//CHANGING VARS
var slideId = 'slide_' + num;
var pageId = slideId;;
var textId = 'text_box_' + num;
var elementId = textId;
var iIndex = num;
//SIZING
var pt350 = {
magnitude: 350,
unit: 'PT',
};
//ALL REQUESTS GO IN requests
var requests = [{
createSlide: {
insertionIndex: iIndex,
objectId: pageId,
slideLayoutReference: {
predefinedLayout: 'BLANK'
}
},
//CREATE THE TEXTBOX
createShape: {
objectId: elementId,
shapeType: 'TEXT_BOX',
elementProperties: {
pageObjectId: pageId,
size: {
height: pt350,
width: pt350,
},
transform: {
scaleX: 1,
scaleY: 1,
translateX: 350,
translateY: 100,
unit: 'PT',
},
},
},
},
//INSERT TEXT
{
insertText: {
objectId: elementId,
insertionIndex: iIndex,
text: txt,
},
}];
//BATCH UPDATE
return slides.presentations.batchUpdate({
presentationId,
resource: {
requests,
},
}, (err, res) => {
if (err) {
error(err);
}else{
console.log('Success');
//INCREASES COUNTER BY 1
num = num + 1;
//ASKS IF A NEW SLIDE WANTS TO BE CREATED
askYOrN ();}});}

它会产生这个错误:

Error: Invalid value at 'requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'createShape'

文本输入和存储正确。有没有人有办法解决吗?提前致谢。

最佳答案

这个修改怎么样?

修改点:

  • createSlidecreateShapeinsertText 放入requests 数组中的每个元素。
  • insertionIndexinsertText 从 0 开始。

修改后的脚本:

请修改requests如下。

var requests = [
{
createSlide: {
insertionIndex: iIndex,
objectId: pageId,
slideLayoutReference: {
predefinedLayout: 'BLANK',
},
},
},
{
//CREATE THE TEXTBOX
createShape: {
objectId: elementId,
shapeType: 'TEXT_BOX',
elementProperties: {
pageObjectId: pageId,
size: {
height: pt350,
width: pt350,
},
transform: {
scaleX: 1,
scaleY: 1,
translateX: 350,
translateY: 100,
unit: 'PT',
},
},
},
},
{
//INSERT TEXT
insertText: {
objectId: elementId,
insertionIndex: iIndex - 1,
text: txt,
},
}
];

备注:

  • 此修改后的脚本假定启用了 Slides API,并且 https://www.googleapis.com/auth/presentations 的范围包含在范围内。

引用资料:

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

关于javascript - 错误 : Invalid value at 'requests[0]' (oneof), 一个字段 'kind' 已经设置。无法设置 'createShape',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53137069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com