对不起,我是Ruby新手,所以这可能是一个愚蠢的问题,我肯定我错过了一些东西。
我正在尝试使用第三方库的谷歌驱动器访问。当使用它时,我需要google/api_client,我假设它是google-api-client gem(我可能在这里错了,这可能是问题。)
我试过重新安装第三方库,我试过使用gem install
和sudo gem install
命令安装google-api-client,但都无济于事。
有人知道如何让这个宝石工作吗?
像这样安装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')