How to use Twitter in Rails, you need a little to understand all this?

I accessed the user via twitter twitter_auth. Here is the code for this.

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 

I am confused when using twitter gem because each example from the docs says:

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

From friends and followers

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

All these errors make sense, because we apply these methods to the class, and not to the object. But how to create an object for this. I have an authorized user, but how to take measures on his profile using the token that we received.

+1
source share
1 answer

Use client instead of Twitter .

You can see here how you should do it.

0
source

All Articles