Skip to content

Instantly share code, notes, and snippets.

@user512
Last active September 14, 2015 02:43
Show Gist options
  • Save user512/83e1cf494001661aee57 to your computer and use it in GitHub Desktop.
Save user512/83e1cf494001661aee57 to your computer and use it in GitHub Desktop.
Twitter Gem cheat sheet

Twitter Gem Cheat Sheet

For documentation, please read this link http://www.rubydoc.info/gems/twitter#Documentation

User location will be a null object if user didn't input location.

Data needed: followers followings

Make client

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

User Object

client.user

User Name

client.user.name

User Screen Name

client.user.screen_name

User Twitter URL

client.user.uri

User website

client.user.website

User Profile Image URL https

client.user.profile_image_uri_https

get all user followers

client.followers => user objects in array

client.followers.each do |follower|
  p follower.name
end

=> p all followers name

get all user followings

client.following => user objects in array

client.following.each do |following|
  p following.name
end

=> p all following names

For future project

client.search(":)", lang: "en", filter:"images", "retweeted": false).take(10).each do |tweet|
p tweet.text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment