我使用以下代码进行了身份验证:
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!
并使用创建文件
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'})
该文档已成功创建,但我无法弄清楚如何将结果文件的所有权设置给我域中的特定用户(如果无法设置所有权,则与其他用户共享)。