使用 Ruby 从 Google API 删除幻灯片

Delete Slide From Google API Using Ruby

我正在尝试从 google 驱动器上的演示文稿中删除一张幻灯片。目前身份验证有效,我能够检索演示文稿并从那里获取我想删除的幻灯片 ID。当我发送删除幻灯片的请求时,它会抛出此错误:

Caught error badRequest: Invalid requests[0]: No request set.

这是我格式化请求的方式

requests = [{ 
            requests: { 
              delete_object: 
                { 
                  object_id: '<slide_id_goes_here>' 
                } 
              } 
           }]

这是我将请求发送到 API

的方式
service = authorize_service(Google::Apis::SlidesV1::SlidesService.new, scopes)
req = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: requests) 
service.batch_update_presentation(presentation_id, req, {})

导致此错误的原因是什么?我应该如何在 ruby 中格式化它?

编辑:

为了获取我要删除的幻灯片 ID,我采用了这种类型的对象

Google::Apis::SlidesV1::Presentation

然后调用

google_slides_api_presentation_object.slides.first.object_id

也许这是我的部分问题?

这个修改怎么样?

修改后的脚本:

delete_object = Google::Apis::SlidesV1::DeleteObjectRequest.new()
delete_object.object_id_prop = "<slide_id_goes_here>"
request = Google::Apis::SlidesV1::Request.new(delete_object: delete_object)
requests = Array.new([request])
batch = Google::Apis::SlidesV1::BatchUpdatePresentationRequest.new(requests: [])
batch.update!(requests: requests)
res = service.batch_update_presentation(presentation_id, batch, {})

参考: