jethr0null / google_calendar

A minimal wrapper around the Google Calendar API

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Calendar

A fast lightweight and minimalist wrapper around the Google Calendar api.

Gem Version Build Status Dependency Status


[sudo] gem install 'google_calendar'


Obtain a Client ID and Secret

  1. Go to the Google Developers Console.

  2. Select a project, or create a new one.

  3. In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the Calendar API.

  4. In the sidebar on the left, select Credentials.

  5. In either case, you end up on the Credentials page and can create your project's credentials from here.

  6. If you haven't done so already, create your OAuth 2.0 credentials by clicking Create new Client ID under the OAuth heading. Next, look for your application's client ID and client secret in the relevant table. You may also create and edit redirect URIs from this page.

Take note of the Client ID as you'll need to add it to your code later.

Find your calendar ID

  1. Visit Google Calendar in your web browser.

  2. In the calendar list on the left, click the down-arrow button next to the appropriate calendar, then select Calendar settings.

  3. In the Calendar Address section, locate the Calendar ID listed next to the XML, ICAL and HTML buttons.

  4. Copy the Calendar ID.


require 'rubygems'
require 'google_calendar'

# Create an instance of the calendar.
cal =     => YOUR_CLIENT_ID, 
                           :client_secret => YOUR_SECRET,
                           :calendar      => YOUR_CALENDAR_ID,
                           :redirect_url  => "urn:ietf:wg:oauth:2.0:oob" # this is what Google uses for 'applications'

puts "Do you already have a refresh token? (y/n)"
has_token = $stdin.gets.chomp

if has_token.downcase != 'y'

  # A user needs to approve access in order to work with their calendars.
  puts "Visit the following web page in your browser and approve access."
  puts cal.authorize_url
  puts "\nCopy the code that Google returned and paste it here:"

  # Pass the ONE TIME USE access code here to login and get a refresh token that you can use for access from now on.
  refresh_token = cal.login_with_auth_code( $stdin.gets.chomp )

  puts "\nMake sure you SAVE YOUR REFRESH TOKEN so you don't have to prompt the user to approve access again."
  puts "your refresh token is:\n\t#{refresh_token}\n"
  puts "Press return to continue"


  puts "Enter your refresh token"
  refresh_token = $stdin.gets.chomp

  # Note: You can also pass your refresh_token to the constructor and it will login at that time.


event = cal.create_event do |e|
  e.title = 'A Cool Event'
  e.start_time =
  e.end_time = + (60 * 60) # seconds * min

puts event

event = cal.find_or_create_event_by_id( do |e|
  e.title = 'An Updated Cool Event'
  e.end_time = + (60 * 60 * 2) # seconds * min * hours

puts event

# All events

# Query events
puts cal.find_events('your search string')

This sample code is located in readme_code.rb in the root folder.


  • This is not a complete implementation of the calendar api, it just includes the features we needed to support our internal calendar integration. Feel free to add additional features and we will happily integrate them.

  • Did you get an SSL exception? If so take a look at this:

Contributing to google_calendar

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2010-2014 Steve Zich. See LICENSE.txt for further details.

ezoic increase your site revenue


A minimal wrapper around the Google Calendar API

License:MIT License


Language:Ruby 100.0%