Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何使用服务帐户从google drive api下载文件?_Ruby_Google Api_Google Drive Api_Google Api Ruby Client - Fatal编程技术网

Ruby 如何使用服务帐户从google drive api下载文件?

Ruby 如何使用服务帐户从google drive api下载文件?,ruby,google-api,google-drive-api,google-api-ruby-client,Ruby,Google Api,Google Drive Api,Google Api Ruby Client,你好,谷歌黑客 我正在使用驱动器服务应用程序并成功上传文件,如下所示: require 'googleauth' require 'google/apis/drive_v2' Drive = Google::Apis::DriveV2 upload_source = "/User/my_user_name/hacking.txt" drive = Drive::DriveService.new # Drive::AUTH_DRIVE is equal to https://www.googl

你好,谷歌黑客

我正在使用驱动器服务应用程序并成功上传文件,如下所示:

require 'googleauth'
require 'google/apis/drive_v2'

Drive = Google::Apis::DriveV2

upload_source = "/User/my_user_name/hacking.txt"
drive = Drive::DriveService.new
# Drive::AUTH_DRIVE is equal to https://www.googleapis.com/auth/drive
drive.authorization = Google::Auth.get_application_default([Drive::AUTH_DRIVE])
file = drive.insert_file({title: 'hacking.txt'}, upload_source: upload_source)
文件
有很多属性,如下所示:

但当我试图在浏览器中打开这个
下载url
时,它会显示一个空白屏幕。为什么我不能下载


我想,那可能是许可问题吧?但是范围是正确的,上传是成功的…

答案很简单-我们无法从
文件
对象下载它,我们必须发送另一个get请求,只需按如下方式下载:

drive.get_file(file.id, download_dest: '/tmp/my_file.txt')

put service.get\u文件(invoice.id,download\u dest:“temp.pdf”)
为我创建了一个空文件。我找到了。必须将令牌权限增加到
Google::api::DriveV2::AUTH\u DRIVE