Giter Club home page Giter Club logo

Comments (3)

markkanof avatar markkanof commented on August 28, 2024

Any chance you could share how you go 2LO working? I've been struggling for a couple of days now with no luck. I've only been able to locate a few examples of people claiming they got it to work and those were either outdates, incomplete, or some combination of the two.

from google-api-ruby-client.

prusswan avatar prusswan commented on August 28, 2024

@markkanof

Mainly by checking the ruby source code and examining the older java client as described here, and logging the actual requests. I only checked Calendar v3 so I'm not sure about the other apis. At least for Calendar the xoauth_requestor_id parameter is needed, Calendar API's documentation also makes mention of the API key for domain-wide delegation 2LO, but I realized it is not needed in my specific example:

Working example of accessing Calendar API v3 using OAuth1 in Ruby

# Initialize the client
require 'debugger'
require 'net-http-spy'
require 'google/api_client'


KEY = 'omitted'
SECRET = 'omitted'
API_KEY = "omitted"

client = Google::APIClient.new(
  :key => API_KEY,
  :authorization => :two_legged_oauth
)

# Block 4: Using 2LO (two_legged_oauth) + API key to access Calendar API
client.authorization.client_credential_key = KEY
client.authorization.client_credential_secret = SECRET

cal = client.discovered_api('calendar','v3')

result = client.execute(
  :api_method => cal.events.list,
  :parameters => {
    'calendarId' => 'primary',
    :key => API_KEY,
    :xoauth_requestor_id => "[email protected]"
  },
)

puts result.data.to_json

  • Output:
16:09:25 prusswan@prusswan-mint dropmyemail (googleapps-integration)$ bundle exec ruby lib/dropmyemail/google_api_test.rb 
I, [2013-06-10T16:10:49.741938 #22077]  INFO -- : CONNECT: ["www.googleapis.com", 443]
I, [2013-06-10T16:10:49.748663 #22077]  INFO -- : GET /discovery/v1/apis/calendar/v3/rest?key=AIzaSyCDQmNRkB2iwFU62ySo77fGMwl98EdLuAc
I, [2013-06-10T16:10:49.847158 #22077]  INFO -- : PARAMS {} 
I, [2013-06-10T16:10:49.847452 #22077]  INFO -- : BODY: Net::HTTPOK
I, [2013-06-10T16:10:49.950445 #22077]  INFO -- : CONNECT: ["www.googleapis.com", 443]
I, [2013-06-10T16:10:49.957003 #22077]  INFO -- : GET /calendar/v3/calendars/primary/events?key=**omitted**&xoauth_requestor_id=support%40dropmyemail.mygbiz.com
I, [2013-06-10T16:10:50.453468 #22077]  INFO -- : PARAMS {} 
I, [2013-06-10T16:10:50.453918 #22077]  INFO -- : BODY: Net::HTTPOK
{"kind":"calendar#events","etag":"\"3HZc1wy_mzFFhn5FKK0rPMjgApI/u9LbHHebzwV8OsntwpnGp1zzwqU\"","summary":"[email protected]","updated":"2013-06-06T08:41:23.420Z","timeZone":"Asia/Singapore","accessRole":"owner","defaultReminders":[{"method":"popup","minutes":10}],"items":[{"kind":"calendar#event","etag":"\"3HZc1wy_mzFFhn5FKK0rPMjgApI/MTM3MDUwNzA3MzM1NjAwMA\"","id":"r1j800h0n32qjjmimfg999aks4","status":"confirmed","htmlLink":"https://www.google.com/calendar/event?eid=cjFqODAwaDBuMzJxamptaW1mZzk5OWFrczQgc3VwcG9ydEBkcm9wbXllbWFpbC5teWdiaXouY29t","created":"2013-06-06T08:24:33.000Z","updated":"2013-06-06T08:24:33.356Z","summary":"Rubber Duck Day","description":"the day when yellow ducks will be liberated all over the country","location":"Tiongland","colorId":"5","creator":{"email":"[email protected]","displayName":"DME Support","self":true},"organizer":{"email":"[email protected]","displayName":"DME Support","self":true},"start":{"date":"2013-06-04"},"end":{"date":"2013-06-05"},"transparency":"transparent","iCalUID":"[email protected]","sequence":0,"reminders":{"useDefault":true}}]}

from google-api-ruby-client.

markkanof avatar markkanof commented on August 28, 2024

@prusswan

Thank you so much! This worked perfectly. After a couple days of trying and failing to get the authentication bits working, it's great to have a solution and be able to move forward with actually writing code to deal with calendar events.

from google-api-ruby-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.