3

你好谷歌黑客!

我正在使用 Drive Service 应用程序并成功上传文件,如下所示:

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)

file有很多属性,比如: download_url

但是当我尝试download_url在浏览器中打开它时,它会显示空白屏幕。为什么我不能下载?

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

4

1 回答 1

3

答案很简单——我们不能从file对象下载它,我们必须发送另一个 get 请求,像这样下载它:

drive.get_file(file.id, download_dest: '/tmp/my_file.txt')
于 2015-08-07T10:17:31.033 回答