0
votes

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?

1

1 Answers

0
votes

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.