First, you donβt need user credentials to get Twitter feed if it is open. Look at Twitter Twitter . After installing the gem, all you have to do is:
require 'twitter' Twitter.user_timeline("icambron")
Try on IRB to get started. Pretty easy, right?
Now, you probably want to use your API key because Twitter restricts anonymous requests, and this can be problematic from a shared server. Do this in the initializer :
Twitter.configure do |config| config.consumer_key = YOUR_CONSUMER_KEY config.consumer_secret = YOUR_CONSUMER_SECRET config.oauth_token = YOUR_OAUTH_TOKEN config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET end
Get the actual values ββfrom the Twitter developer page.
Finally, to really like it, if you want to scale up, you can make a request on behalf of the user using the OAuth credentials you received from OmniAuth (NOT their username and password, you do not have these). This will allow you to make more requests per second, because they come from different users. Just initialize Twitter with the consumer_key and consumer_secret fields set for the things you got from the OmniAuth hash (see here , see the credentials section to see how to get them from OmniAuth).
user24359
source share