Question

I'm using google-api-client (0.3.0) gem for my Rails app to access a user's data through Google Drive API v2.

I successfully searched for a file by title and then tried to use the file id from the search result to insert a new permission. I want to programmatically allow "anyone with the link" to comment on the file.

Following the sample code here: https://developers.google.com/drive/v2/reference/permissions/insert, I wrote the following code:

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

I got a 400 error. Here is the hash dump:

--- !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.

According to errors.rb in the gem source code, a 4xx error is a client error.

Any help fixing this bug would be greatly appreciated.

Was it helpful?

Solution

Likely an issue in that version of the client library and there were significant changes between 0.3 and 0.4. I ran the same snippet on the current version 0.4.4 and it worked fine. Suggest updating your dependency if at all possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top