如何在Rails中使用Twitter gem,需要小才能搞清楚整个事情?

我使用twitter_auth gem访问了用户。 这是代码。

def twitter client = TwitterOAuth::Client.new( :consumer_key => '******', :consumer_secret => '********' ) request_token = client.request_token(:oauth_callback => new_user_url) session[:request_token] = request_token redirect_to request_token.authorize_url end def new client = TwitterOAuth::Client.new( :consumer_key => '*****', :consumer_secret => '******' ) access_token = client.authorize( session[:request_token].token, session[:request_token].secret, :oauth_verifier => params[:oauth_verifier] ) #For testing purpose, i tried posting a status and its working perfectly fine client.update('I am authorized') end 

我很困惑使用twitter gem因为文档中的每个例子都说:

  Twitter.user("sferik").location // throws an error, Twitter::Error::Unauthorized: Invalid / expired Token 

来自朋友和粉丝

  Twitter.accept("sferik") // throws an error, Twitter::Error::Unauthorized: Invalid / expired Token Twitter.follow("sferik") // throws an error, Twitter::Error::Unauthorized: Invalid / expired Token 

所有这些错误都有意义,因为我们在Class上应用这些方法而不是对象。 但是如何为此创建一个对象。 我有一个授权用户,但如何使用我们获得的令牌对他的个人资料采取行动。

使用client而不是Twitter

你可以在这里看到你应该怎么做。