Search code examples
ruby-on-railsapioauthoauth-ruby

Google Calendar Data API Integration


We're using Oauth to grab Calendar event data. I have successfully authorized the token and exchange it for an access token. When I perform a get request to the API endpoint I get a page that says "Moved Temporarily" with a link to something like https://www.google.com/calendar/feeds/default?gsessionid=xxxxxxxxxxxx

I'd like to interpret the response, whether it's json or xml but I can't get beyond the redirect it's throwing out. Any idea how to follow this?

Here's my call to the feed:

    access_token = current_user.google.client
    response = access_token.get(ConsumerToken::GOOGLE_URL).body

Solution

  • Yep, just dealt with this myself. It says "Moved Temporarily" because it's a redirect, which the oauth gem unfortunately doesn't follow automatically. You can do something like this:

    calendar_response = client.get "http://www.google.com/calendar/feeds/default"
    if calendar_response.kind_of? Net::HTTPFound # a.k.a. 302 redirect
      calendar_response = client.get(calendar_response['location'])
    end
    

    This might be worthy of a patch to oauth...