bahhh, never mind. Here's the code in a gist:

https://gist.github.com/1346963

Sorry for the list spam.



On Nov 7, 7:54 pm, tks <[email protected]> wrote:
> Attempt to fix formatting of code examples:
>
> 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
>   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
>
> On Nov 7, 7:35 pm, tks <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello,
>
> > I am trying to set up my Rails application to connect to the 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_protoc...
>
> > 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 
> > threadhttp://groups.google.com/group/google-calendar-help-dataapi/browse_th...
> > 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
> >         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

-- 
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html

Reply via email to