Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How access Google Contacts using OpenID in Ruby

I am using devise to login with omniauth, authid. When the user is logged in I get

user_info: 
name: Riccardo Tacconi
last_name: Tacconi
email: [email protected]
first_name: Riccardo
uid: https://www.google.com/accounts/o8/id?id=xxxxxxxxx
provider: google_apps

I have found a plug-in: http://stakeventures.com/articles/2009/10/06/portable-contacts-in-ruby to get the Google Contacts. I only need to use this method:

@client = PortableContacts::Client.new "http://www-opensocial.googleusercontent.com/api/people", @access_token

but I need a token. I only have the uid. Do you have an idea how to get the access token? There is not any doc about accessing google.

like image 603
rtacconi Avatar asked Dec 01 '10 13:12

rtacconi


1 Answers

The answer to this one is fairly complicated. Pelle's Portable Contacts parser relies on his oauth gem. You might be able to manually construct the token object (a key/secret pair) from whatever omniauth/authid gives you, but it's likely to be some pretty messy code.

The officially supported OAuth client for Ruby is Signet. However, Pelle's parser was only designed for use with his OAuth implementation, so again, the story here is about the same. You might be able to rip out the parsing code from his client and marry it to Signet, but as before, if you go down that route, you've got your work cut out for you.

Probably the easiest thing to do today is to just use the oauth gem and accept the dependency tree that Pelle forced on you.

Edit: It's awhile later and the google-api-client gem may provide you with what you need at this point. Supports both OAuth 1 and 2 and offers discovery-based access to certain Google APIs in many cases. Unfortunately the Contacts API is not currently on the list but the client is still capable of making requests to APIs without using discovery, though it's a bit more manual in that case (in that you need to pass it HTTP requests which it will authorize and you're basically on your own for parsing).

like image 50
Bob Aman Avatar answered Oct 18 '22 21:10

Bob Aman