我正在使用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错误是客户端错误。
任何帮助修复这个错误将不胜感激。
我不熟练Ruby,但也许你可以登录HTTP请求,看看发生了什么。现在看起来像客户端库中的一个bug,除非有办法将其配置为执行表单编码的帖子vs JSON帖子 – Nivco 2012-07-26 13:13:52