0

Sorry, I'm new to Ruby so this may be a dumb question to ask, I'm sure I'm missing something.

I'm trying to use a 3rd party library for Google Drive access. When using it, I need to require google/api_client, which I assume is the google-api-client gem (I could be wrong here, and this could be the issue.)

I've tried reinstalling the 3rd party library, and I've tried installing google-api-client using gem install and sudo gem install commands, but all to no avail.

Anyone know how to get this gem working?

Bill L
  • 2,576
  • 4
  • 28
  • 55

1 Answers1

0

Install the gem like this:

gem install google-api-client --pre

Then, to use drive api, use:

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')

See this for more instruction and usage.

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • For those curious `--pre` allows installation of prerelease versions. `google-api-client` is currently in alpha status so you have to explicitly want to install the unstable version. – abraham Aug 25 '15 at 14:57