使用 Ruby Google Slides API 更新形状颜色



我正在尝试使用Ruby中的谷歌幻灯片API更新省略号形状。这是代码:

shape_properties = {
shape_background_fill: {
solid_fill: {
color: {
rgb_color: {
red: 1.0,
green: 0,
blue: 0
}
}
}
}
}
requests = [{
update_shape_properties: {
object_id: ellipse.object_id,
fields: 'shapeBackgroundFill',
shape_properties: shape_properties,
},
}]
# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = @slides.batch_update_presentation(presentation_id,req)

我尝试过的另一个相同错误的代码是这个:

rgb_color = Google::Apis::SlidesV1::RgbColor.new(red: 1.0, green: 0, blue: 0)
color = Google::Apis::SlidesV1::OpaqueColor.new(rgb_color: rgb_color)
solid_fill = Google::Apis::SlidesV1::SolidFill.new(color: color)
shape_background_fill = Google::Apis::SlidesV1::ShapeBackgroundFill.new(solid_fill: solid_fill)
shape_properties = Google::Apis::SlidesV1::ShapeProperties.new(shape_background_fill: shape_background_fill)
requests = [{
update_shape_properties: {
object_id: ellipse.object_id,
fields: 'shapeBackgroundFill',
shape_properties: shape_properties,
},
}]
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests)
response = @slides.batch_update_presentation(presentation_id, req)

我收到此错误:

`check_status': badRequest: Invalid requests[0].updateShapeProperties: The object () could not be found. (Google::Apis::ClientError)

知道为什么会失败吗?

尝试在update_shape_properties中使用object_id_prop而不是object_id

shape_properties = {
shape_background_fill: {
solid_fill: {
color: {
rgb_color: {
red: 1.0,
green: 0,
blue: 0
}
}
}
}
}
requests = [{
update_shape_properties: {
object_id_prop: ellipse.object_id,
fields: 'shapeBackgroundFill',
shape_properties: shape_properties,
},
}]
# Execute the request.
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: 
requests)
response = @slides.batch_update_presentation(pres`entation_id,req)

因为 UpdateShapePropertiesRequest 具有object_id_prop访问器而不是object_id。 这就是为什么object_id名称已经在 Object 中使用的原因。