【问题标题】:Update shape color using Ruby Google Slides API使用 Ruby Google Slides API 更新形状颜色
【发布时间】:2018-05-18 09:35:39
【问题描述】:

我正在尝试使用 ruby​​ 中的 google slides 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)

知道为什么会失败吗?

【问题讨论】:

  • 找不到对象()。听起来你没有发送对象
  • @DaImTo 我已经更新了帖子,并再次尝试确保我正在发送一个对象,但我遇到了同样的错误

标签: ruby google-api google-api-client google-slides-api google-slides


【解决方案1】:

尝试在 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 中使用的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 2011-12-25
    • 2014-04-04
    相关资源
    最近更新 更多