【问题标题】:Delete Slide From Google API Using Ruby使用 Ruby 从 Google API 中删除幻灯片
【发布时间】:2018-09-13 21:06:47
【问题描述】:

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

捕获错误 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

也许这是我的问题的一部分?

【问题讨论】:

  • 对不起。我的复制和粘贴是错误的。我修改错误。请求不是数组。虽然我不确定这是否是您的情况的直接解决方案,但是从requests=[{requests:{delete_object:{object_id:'&lt;slide_id_goes_here&gt;'}}}] 修改为requests={requests:{delete_object:{object_id:'&lt;slide_id_goes_here&gt;'}}} 怎么样?如果这不起作用,我很抱歉。
  • 感谢您的回复。不幸的是,这似乎并没有解决问题,因为它继续返回相同的错误。回到绘图板我猜。
  • 我发布了一个答案。你能确认一下吗?在我的环境中,我可以确认它有效。请在您的环境中尝试。使用时,请在作用域中包含Google::Apis::SlidesV1::AUTH_PRESENTATIONS

标签: ruby-on-rails ruby google-slides-api


【解决方案1】:

这个修改怎么样?

修改脚本:

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, {})

参考:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    相关资源
    最近更新 更多