Sinatra example of authenticating and uploading images to Twitter.
Sinatra example of authenticating and uploading images to Twitter.
Have not seen an updated Twitter Auth/Post example. Here is a solution in ~100 lines in Ruby.
Our company needed the ability to post Images, so this was a nice playground for that.
Feel free to fork/PR.
First and foremost, you must have an set of consumer keys from Twitter. Here is the URL to start that process, https://apps.twitter.com/.
Second open a Terminal
# Install required Gems
bundle
# Setup Twitter Environment Variables
cp env.example env.local
# Open local and enter values for CONSUMER_KEY and CONSUMER_SECRET
source env.local
# Start websever
ruby ./main.rb
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.2 codename Doc Brown)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
...
Now open the browser to http://127.0.0.1:4567/login to start the 3-Legged Authorization process with Twitter.
After the Twitter callback succeeds, navigate to the /test
to view your OAuth credentials.
After authenticating, to post a tweet, navigate to the /post/message/
route. Here are some examples.
After authenticating, to post a tweet with an image, navigate to the /post/image/
route. Here are some examples.
To test the authentication process, you can logout and attepmpt to post again.