Below is how I setup Ruby, Rails, Gem and a command-line twitter tool to query Twitter on Ubuntu 16.04 via a Twitter App
Setup Twitter feed scraping on Ubuntu 16.04
At first, I had no network (I could not ping, run a system update or install packages (even though I had opened the firewall ports and disabled the firewall temporarily)? I fixed this by editing /etc/resolv.conf and added a google DNS entry.
Added the Google DNS server.
Bingo, I can now ping and update my system.
Setup Ruby and Pre-Requisites
If ruby 2.4.1 fails o install try and install the older ruby 2.2.1
Error
Optional Troubleshooting: Install Ruby 2.2.1 (if 2.4.1 fails to install)
Optional Troubleshooting: Ruby 2.2.1 is no longer recommended
Or
Optional Install: Ruby 2.4.0
Hopefully, Ruby is now installed
Install Bundler Gem
Install Rails
I skipped the Install (as I had node installed).
Continue with rails install
Rails is installed
Install the t gem (read more at the https://github.com/sferik/t GitHub repository)
You can now authorize the t gem to use your twitter.
But first let’s create a twitter app.
Goto https://apps.twitter.com/, login and create an app.
Twitter will provide app details when you create the app.
Go to Permissions and set “Read, Write and Access direct messages” and save changes.
Linking the Twitter app to t Gem
Now that the Twitter app is created let’s activate and link it to the t gem,
Run the following command to start the authorization process.
The authorization process is dead simple, just follow the on-screen prompts.
This was easy.
fyi: Authorization (Twitter authorize app screenshot)
fyi: Authorization (Twitter authorize app pin screenshot)
Using T
T Help
Show linked twitter accounts with t
Show authorized twitter accounts
t set active yourtwitterappnamehere ######################## Active account has been updated to yourtwitterappnamehere.
Using t to query a Twitter user
Search Twitter for “fearby”
Output:
Search Twitter for “fearby” (max 10) and output at CSV
See more commands here: https://github.com/sferik/t
This is great, I can interact with Twitter from the command line and apps without having to go full REST API and OAUTH development.
Calling T from NodeJS
Read the guide here on calling T from NodeJS.
Calling T from php (Under construction)
Coming soon (this PHP section is under development)
You may need to exclude “pcntl_exec” from being blocked in “php.ini” under “disable_functions”
find your php.ini by typing
Restart php
sudo service php7.0-fpm restart php7.0-fpm stop/waiting php7.0-fpm start/running, process ##### user@servername:/www# service php7.0-fpm status php7.0-fpm start/running, process #####
This section is under development,
Todo: Security.
Need a server?
Set up a Server on Vultr here for as low as $2.5 a month or set up a Server on Digital Ocean (and get the first 2 months free ($5/m server)). I have a guide on setting up a Vultr server here or Digital Ocean server here. Don’t forget to add a free LetsEncrypt SSL Certificate and secure the server (read more here and here).
Still here, read more articles here or use the form below to ask a question or recommend an article.
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]
Version History
v1.3.2 added Ruby 2.2.0 install info (29th Sep 2017)
v1.3.1 added Ruby 2.2.1 install info (27th Sep 2017)
v1.3 Querying T in NodeJS