【问题标题】:code: 400 error when trying to insert a new permission using Google Drive API v2代码:尝试使用 Google Drive API v2 插入新权限时出现 400 错误
【发布时间】:2012-07-27 05:08:31
【问题描述】:

我正在为我的 Rails 应用程序使用 google-api-client (0.3.0) gem 来通过 Google Drive API v2 访问用户的数据。

我成功按标题搜索文件,然后尝试使用搜索结果中的文件 ID 插入新权限。我想以编程方式允许“知道链接的任何人”对文件发表评论。

按照这里的示例代码:https://developers.google.com/drive/v2/reference/permissions/insert,我编写了以下代码:

new_permission = gDriveApi.permissions.insert.request_schema.new({ 
                         'role' => "reader",
                         'type' => "anyone",
                         'value' => "",
                         'additionalRoles' => ["commenter"], 
                         'withLink' => true })

result = client.execute(:api_method => gDriveApi.permissions.insert,
                        :body_object => new_permission,
                        :parameters => { 'fileId' => file_id })

我收到 400 错误。这是哈希转储:

--- !ruby/object:Google::APIClient::Schema::Drive::V2::Permission 
data: 
  error: 
    errors: 
    - domain: global reason: parseError 
      message: This API does not support parsing form-encoded input.
    code: 400 
    message: This API does not support parsing form-encoded input.

根据gem源代码中的errors.rb,4xx错误是客户端错误。

任何帮助修复此错误将不胜感激。

【问题讨论】:

  • 我不精通 Ruby,但也许您可以记录 HTTP 请求以查看发生了什么。不过,目前它似乎是客户端库中的一个错误,除非有办法将其配置为执行表单编码的帖子与 JSON 帖子

标签: google-drive-api


【解决方案1】:

该版本的客户端库中可能存在问题,并且在 0.3 和 0.4 之间发生了重大变化。我在当前版本 0.4.4 上运行了相同的 sn-p,它运行良好。如果可能,建议更新您的依赖项。

【讨论】:

  • 将 google-api-client gem 更新到 0.4.3 解决了这个问题。非常感谢,史蒂夫!
猜你喜欢
  • 1970-01-01
  • 2020-06-08
  • 2012-06-24
  • 2014-04-22
  • 2022-01-02
  • 1970-01-01
  • 2016-01-09
  • 2014-11-05
  • 1970-01-01
相关资源
最近更新 更多