Skip to content

Instantly share code, notes, and snippets.

@alejandrobabio
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrobabio/f14ad6545e24d25eec02 to your computer and use it in GitHub Desktop.
Save alejandrobabio/f14ad6545e24d25eec02 to your computer and use it in GitHub Desktop.
Script for read google drive
require 'google_drive'
client = Google::APIClient.new(application_name: 'Google Drive Ruby test', application_version: '0.0.1')
key = Google::APIClient::KeyUtils.load_from_pkcs12(
'path to your p12 key file (all the path with file name)',
'your secret here given at download file it seems to be always the same: notasecret')
asserter = Google::APIClient::JWTAsserter.new(
'service account - email address - here',
['https://www.googleapis.com/auth/drive'],
key
)
client.authorization = asserter.authorize
session = GoogleDrive.login_with_oauth(client.authorization.access_token)
# access data
# all files shared with the 'email address' at asserter
session.files { |file| puts file }
# some spreadsheet
spreadsheet = session.spreadsheet_by_key('the alpha key at the link')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment