OmniAuth +拉动推文,FB场所等

我正在使用OmniAuth + Devise允许用户使用附加到普通用户帐户的Facebook / Twitter / Gowalla / etc进行注册。 现在,当用户使用其中任何一个或他们的帐户登录时,他们所有的社交网络都附加在身份validation表中。

我需要能够从任何这些提供商中提取内容,例如他们的推文或他们的Facebook Places检查等。我知道我需要使用不同的gem,插件,无论做什么,但获得我需要的配置使用这些gem(并提出请求)让我很困惑。

我需要能够访问omniauth.rb中的提供程序配置项,因此我有API密钥和密钥等,然后我需要能够从oAuth的东西中获取令牌来发出请求。

其他gem如https://github.com/jrallison/authlogic_oauth似乎存储了oauth_token,oauth_secret和oauth_token,但OmniAuth没有。

你可能会说我对Ruby,Rails和oAuth都很陌生,所以这是一个非常具有挑战性的应用程序。 非常需要帮助。

排序!

在http://railscasts.com/episodes/236-omniauth-part-2中描述的身份validation表中添加了令牌和机密,但更改了authentication.build行以获取另外两个参数:

authentications.build( :provider => omniauth['provider'], :uid => omniauth['uid'], :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'] ) 

然后使用http://dev.twitter.com/pages/oauth_single_token#ruby中的代码示例

 class CronController < ApplicationController def recent_tweets # Exchange your oauth_token and oauth_token_secret for an AccessToken instance. def prepare_access_token(oauth_token, oauth_token_secret) consumer = OAuth::Consumer.new("APIKey", "APISecret" { :site => "http://api.twitter.com" }) # now create the access token object from passed values token_hash = { :oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret } access_token = OAuth::AccessToken.from_hash(consumer, token_hash ) return access_token end auth = current_user.authentications.find(:first, :conditions => { :provider => 'twitter' }) # Exchange our oauth_token and oauth_token secret for the AccessToken instance. access_token = prepare_access_token(auth['token'], auth['secret']) # use the access token as an agent to get the home timeline response = access_token.request(:get, "http://api.twitter.com/1/statuses/home_timeline.json") render :json => response.body end end 

通过从current_user.authentications(我找到第一个,因为他们应该只有一个)中提取内容,我可以获取令牌和安全性,并且它很好。

现在我可以调整一下,保存一些东西,使用JSON,并采取我需要的东西。 我相信Facebook会非常相似。

这是你在找什么? http://railscasts.com/episodes/236-omniauth-part-2 :)它显示了如何检索电子邮件等数据。 不确定这是不是你想要的。