You need to use the permissions feed to add permissions. See the document on sharing, and the drive.permissions.insert
method, which has a Ruby example:
How do I set permissions on a file that was created using files.insert with a Web Service OAuth credential?
-
13-01-2022 - |
Question
I did authentication with the following code:
key = Google::APIClient::KeyUtils.load_from_pkcs12(path_to_key_file, 'notasecret')
@client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/drive',
:issuer => 'xxx@developer.gserviceaccount.com',
:signing_key => key)
@client.authorization.fetch_access_token!
and created the file using
file = @drive.files.insert.request_schema.new({
'title' => title,
'description' => description,
'mimeType' => mime_type
})
media = Google::APIClient::UploadIO.new(file_name, mime_type)
result = @client.execute(
:api_method => @drive.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'multipart',
'convert' => true,
'alt' => 'json'})
The document is created successfully, but I can not figure out how to set the resulting file's ownership to a specific user within my domain (or share it with another user if setting ownership is not possible).
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow