Closed cthulhu666 closed 4 years ago
Can we also show an example using the body_object, was stuck on that for a while when trying to use the create a new gmail draft. It doesn't 'fit' in the example but can include as a separate file.
require 'google/api_client'
# user = User.find(x)
client = Google::APIClient.new
client.authorization.client_id = ENV['GOOGLE_CLIENT_ID']
client.authorization.client_secret = ENV['GOOGLE_CLIENT_SECRET']
client.authorization.grant_type = 'refresh_token'
client.authorization.refresh_token = user.refresh_token
client.authorization.fetch_access_token!
gmail = client.discovered_api('gmail', 'v1')
result = client.execute(
api_method: gmail.users.drafts.create,
parameters: { 'userId' => 'me' },
body_object: { 'message' =>
{ 'raw' => Base64.urlsafe_encode64(user.message) }
}
)
+1 @sgomes @icco
Sinatra app talking with the new Gmail API. Based on Calendar API sample.