Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6951185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:11:15+00:00 2026-05-27T14:11:15+00:00

I am trying to set up my Rails application to connect to the google

  • 0

I am trying to set up my Rails application to connect to the google calendar
api. I am following the Oauth2 documentation here:

http://code.google.com/apis/accounts/docs/OAuth2.html#SS

and the instructions for creating a single event on a user’s private
calendar here:

http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#CreatingSingle

I have been able to generate the Oauth2 access and refresh tokens
using the server side strategy, but whenever I query the api I get the
following error:

{“apiVersion”:”2.6″,”error”:{“code”:400,”message”:”Invalid
JSON”,”errors”:
[{“domain”:”GData”,”code”:”invalidJson”,”internalReason”:”Invalid
JSON”}]}}

(This is the same error given in this thread
http://groups.google.com/group/google-calendar-help-dataapi/browse_thread/thread/2171226629b28c3b
except I am passing GData-Version: 2 into the http post header, so the
apiVersion is different )

The json I am using is the example event data given in the protocol
document in the second reference link above. As far as I can tell this
is generally happening after the second time I query the api after
getting the 302 redirect. Would greatly appreciate it if someone would
explain what this error means and how to get around it. I’m including
the relevent code from my app below:

EventController.rb

event_hash = { :data => {
                 :title => "Tennis with Beth",
                 :details => "Meet for a quick lesson.",
                 :transparency => "opaque",
                 :status => "confirmed",
                 :location => "Rolling Lawn Courts",
                 :when => [{
                   :start => "2012-04-17T15:00:00.000Z",
                   :end => "2012-04-17T17:00:00.000Z"
                   }]
                }
              }

event_data = event_hash.to_json

auth_string = "Bearer " + google_oauth2_credential.access_token # gets access token for user
header_hash = { 'Content-Type' => 'application/json', 'Authorization' => auth_string, 'GData-Version' => '2' }

response = post_to_https('https://www.google.com/calendar/feeds/default/private/full', event_data, header_hash) # note see ApplicationController paste below to see the post_to_https method

if response.code == '302'
  uri_string = response.response['Location']
  response = post_to_https(uri_string, event_data, header_hash)
  render :text => "302 " + response.body
else
    render :text => "not 302 " + response.body)
end

ApplicationController.rb

def post_to_https(url_string, params_hash, header_hash = {})
  uri = URI.parse(url_string)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(params_hash)

  unless header_hash.empty?
    header_hash.each { |key, value| request[key] = value }
  end
  return http.request(request)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:11:16+00:00Added an answer on May 27, 2026 at 2:11 pm

    Most of the problems you’re discussing here should not occur if you use the latest version of the API and the Ruby client library, as documented here:

    http://code.google.com/apis/calendar/v3/using.html#setup

    page_token = nil
    result = result = client.execute(:api_method => service.events.list,
                                     :parameters => {'calendarId' => 'primary'})
    while true
      events = result.data.items
      events.each do |e|
        print e.summary + "\n"
      end
      if !(page_token = result.data.next_page_token)
        break
      end
      result = result = client.execute(:api_method => service.events.list,
                                       :parameters => {'calendarId' => 'primary', 'pageToken' => page_token})
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey! I am trying to set up routes in a Rails application so that,
I'm currently trying to set up integration/acceptance testing for a new rails 3 application
I'm trying to integrate the solution listed here into my rails (3.1) application. I
I'm trying to set up a rails 2.2.2 application in Mac OS X Lion.
I am trying to set up as has_and_belongs_to_many relationship in my rails application, between
I'm using following code to configure logging in my Ruby on Rails application: environment.rb:
I'm trying to set some class variables to store paths in a Rails application
I'm trying to dry up some code in my Rails application that allows to
I am trying to set up Rails tests with MS SQL server. Currently Rails
I started trying to set up a local rails installation for development. After I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.