Skip to content

Instantly share code, notes, and snippets.

@MaxPleaner
Last active August 29, 2015 14:02
Show Gist options
  • Save MaxPleaner/d2043e9b9960626104ff to your computer and use it in GitHub Desktop.
Save MaxPleaner/d2043e9b9960626104ff to your computer and use it in GitHub Desktop.
Twitter client (broken)
require 'json'
require 'simple_oauth'
require 'excon'
require 'nokogiri'
require_relative 'lib/twitter_creds'
def post_tweet(string)
authorization_header = SimpleOAuth::Header.new("post",
"https://api.twitter.com/1.1/statuses/user_timeline.json",
{ :screen_name => "ugly_name",
:text => string },
{ :consumer_key => API_KEY,
:consumer_secret => API_SECRET,
:token => ACCESS_TOKEN,
:token_secret => ACCESS_TOKEN_SECRET })
response = Excon.send("post", "https://api.twitter.com/1.1/statuses/user_timeline.json", {
:query => { :screen_name => "macsplean",
:text => string },
:headers => { "Authorization" => authorization_header.to_s }
})
puts response.body
puts response.status
end
if __FILE__ == $0
post_tweet("asjdmnaskd")
end
@MaxPleaner
Copy link
Author

Here's what I get when I run this:

max@max-INVALID twitter-client $ ruby scratch.rb
{"errors":[{"message":"Could not authenticate you","code":32}]}
401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment