我正在使用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