How access Google Contacts using OpenID in Ruby

蓝咒 提交于 2019-12-10 13:34:18

问题


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@gmail.com
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.


回答1:


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).



来源:https://stackoverflow.com/questions/4324812/how-access-google-contacts-using-openid-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!