2012-07-26 104 views
2

我正在使用google-api-client(0.3.0)gem为我的Rails应用通过Google Drive API v2访问用户的数据。代码:尝试使用Google Drive API v2插入新权限时出现400错误

我成功按标题搜索文件,然后尝试使用搜索结果中的文件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错误是客户端错误。

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

+0

我不熟练Ruby,但也许你可以登录HTTP请求,看看发生了什么。现在看起来像客户端库中的一个bug,除非有办法将其配置为执行表单编码的帖子vs JSON帖子 – Nivco 2012-07-26 13:13:52

回答

2

该版本的客户端库可能存在问题,并且在0.3和0.4之间有重大更改。我在当前版本0.4.4上运行了相同的代码片段,它运行良好。建议尽可能更新您的依赖关系。

+0

将google-api-client gem更新为0.4.3修复了问题。非常感谢,史蒂夫! – user1553406 2012-07-27 02:07:15

相关问题