找不到Google API Gem

时间:2015-08-24 15:42:36

标签: ruby google-api google-api-ruby-client

抱歉,我是Ruby的新手,所以这可能是一个愚蠢的问题,我确定我错过了什么。

我正在尝试使用第三方库进行Google云端硬盘访问。使用它时,我需要google / api_client,我认为这是google-api-client gem(我可能在这里错了,这可能就是问题。)

我尝试重新安装第三方库,我尝试使用gem installsudo gem install命令安装google-api-client,但都无济于事。

任何人都知道如何让这个宝石工作?

1 个答案:

答案 0 :(得分:0)

像这样安装gem:

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