Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Ruby on Rails controller action showing how to fetch a group of Tweets/followers/friends & send them to a view. You can also create Tweets with this controller & the Twitter API, but you'll need to ensure your callback URL is correct. Follow the documentation for that.
class TweetsController < ApplicationController
before_action :create_client
def index
batch_size = 10
@twitter_handle = "dhh"
@tweets = @client.user_timeline(@twitter_handle).take(batch_size)
@friends = @client.friends(@twitter_handle).take(batch_size)
@followers = @client.followers(@twitter_handle).take(batch_size)
# You can only get mentions for the authenticated user, not any handle you pass to the client.
# @mentions = @client.mentions_timeline.take(batch_size)
def new
# Make sure to set your Twitter app's callback URL to:
# puts @client.update("I'm tweeting with my app!").inspect
render 'index'
# This is a sample of how you'd search for tweets via a full API call URL
# Retrieve latest tweet for @dhh
# Go to OAuth tool in your app settings
# Do a GET request to the following:
# (API docs -
# Copy the cURL signature
# Paste into your command line
# Copy the big response
# Paste in to
# Check it out
def create_client
@client = do |config|
config.consumer_key = " "
config.consumer_secret = " "
config.access_token = " "
config.access_token_secret = " "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.