Skip to content

Instantly share code, notes, and snippets.

@nowlinuxing
Created November 4, 2013 18:27
Show Gist options
  • Select an option

  • Save nowlinuxing/7307059 to your computer and use it in GitHub Desktop.

Select an option

Save nowlinuxing/7307059 to your computer and use it in GitHub Desktop.
Use Twitter via API
# use twitter.gem earlier than 5.0.0
require "pp"
require "twitter"
# 1. Comment out oauth_token and oauth_token_secret.
# 2. Visit https://dev.twitter.com/apps/new. Get consumer_key and consumer_secret.
# 3. Execute.
# 4. Visit the Developper's site agein.
# 5. Go to "settings", and get oauth_token and oauth_token_secret.
# 6. Change "Application Type" to "Read, Write and Access direct messages". Wait for a momenet to reflect.
Twitter.configure do |config|
config.consumer_key = "CONSUMER_KEY"
config.consumer_secret = "CONSUMER_SECRET"
end
client = Twitter::Client.new(
oauth_token: "OAUTH_TOKEN",
oauth_token_secret: "OAUTH_TOKEN_SECRET"
)
#pp Twitter.update("I'm tweeting with gem 'twitter'.")
#pp client.user("gem")
pp client.direct_message_create("", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment