安裝寶石是這樣的:
gem install google-api-client --pre
然後,使用驅動器API,使用:
require 'google/apis/drive_v2'
Drive = Google::Apis::DriveV2 # Alias the module
drive = Drive::DriveService.new
drive.authorization = authorization # See Googleauth or Signet libraries
# Search for files in Drive (first page only)
files = drive.list_files(q: "title contains 'finances'")
files.items.each do |file|
puts file.title
end
# Upload a file
metadata = Drive::File.new(title: 'My document')
metadata = drive.insert_file(metadata, upload_source: 'test.txt', content_type: 'text/plain')
# Download a file
drive.get_file(metadata.id, download_dest: '/tmp/myfile.txt')
更多的指導和用法請參見this。
對於那些好奇的'--pre'允許安裝預發佈版本。 'google-api-client'目前處於alpha狀態,所以你必須明確地想要安裝unstable版本。 – abraham