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

时间:2018-05-18 09:35:39

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

我尝试使用ruby中的google slide 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)

知道为什么会失败吗?

1 个答案:

答案 0 :(得分:0)

尝试在update_shape_properties中使用static navigationOptions = ({ navigation }) => { return { // snip... headerLeft:( <TouchableOpacity onPress={() => navigation.toggleDrawer()} // remove "this.props" here style={{padding:10}}> <Icon size={27} name='ios-menu' color='#fff' /> </TouchableOpacity> ), // snip... }; }; 代替object_id_prop

object_id

因为UpdateShapePropertiesRequest具有object_id_prop访问者而不是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) 访问者。 这就是object_id名称已在对象中使用的原因。