Created
January 5, 2015 19:53
-
-
Save chiastolite/d5443accb886126d4e8f to your computer and use it in GitHub Desktop.
This file contains 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
require 'bundler/setup' | |
Bundler.require | |
require 'google/api_client' | |
require 'google/api_client/client_secrets' | |
require 'google/api_client/auth/installed_app' | |
client = Google::APIClient.new( | |
:application_name => 'Example Ruby application', | |
:application_version => '1.0.0' | |
) | |
key = Google::APIClient::KeyUtils.load_from_pkcs12('./tsundoku.p12', 'notasecret') | |
client.authorization = Signet::OAuth2::Client.new( | |
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token', | |
:audience => 'https://accounts.google.com/o/oauth2/token', | |
:scope => 'https://www.googleapis.com/auth/gmail.readonly', | |
:issuer => my_email, | |
:signing_key => key) | |
client.authorization.fetch_access_token! | |
gmail = client.discovered_api('gmail', "v1") | |
emails = client.execute( api_method: gmail.users.messages.list, | |
parameters: { | |
userId: "me", | |
}, | |
headers: {'Content-Type' => 'application/json'} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment