Created
December 18, 2015 19:55
-
-
Save raymyers/4b425eb1d1874ab51c64 to your computer and use it in GitHub Desktop.
Example Google Drive ruby API usage with google-api-client version 0.9.pre4 authenticating with a service account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = "#{ENV['HOME']}/google-service-account.json" | |
scopes = ['https://www.googleapis.com/auth/drive'] | |
drive = Google::Apis::DriveV2::DriveService.new | |
auth_client = Google::Auth.get_application_default(scopes).dup | |
auth_client.sub = '[email protected]' | |
drive.authorization = auth_client | |
report_folders = drive.list_files(q: "title = 'Reports'") | |
raise "Expected 1 folder called 'Reports', found #{report_folders.items.count}" if report_folders.items.count != 1 | |
parent_id = report_folders.items[0] | |
source = StringIO.new("Content") | |
file_metadata = {title: 'test.txt', parents: [parent_id]} | |
inserted_metadata = drive.insert_file(file_metadata, upload_source: source, content_type: 'text/plain') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment