Social Media from the Command Line, Part 1: Facebook and Twitter

This article is part of the Social Media from Command Line series:

Be the envy of all your geekiest friends by using command-line programs to access your favorite sites and online tools. After reading this article series, you’ll be able to update your status on Facebook and Twitter, post to your Blogger and Tumblr accounts, watch YouTube videos, and manage your Flickr albums all from the comfort of your terminal. Today in Part 1, we’ll cover Facebook and Twitter. Let’s go!

You can access most of Facebook’s main features from your Linux, Mac, or Windows command line with fbcmd.

social-fbcmd-main

Installation

You need to have PHP installed on your system before you can install FBCMD. Once you’ve gotten that out of the way, go ahead and grab the file “fbcmd_update.php”; you can manually download it here or run the following command:

wget https://raw.github.com/dtompkins/fbcmd/master/fbcmd_update.php

Next run these two commands:

php fbcmd_update.php
php fbcmd_update.php install

FBCMD is now installed, but you still need to perform a series of steps to authorize it to access your Facebook account. In your default web browser, log in as the user you want to perform the authorization for. This command will then take you to the basic authorization page:

fbcmd go access

social-fbcmd-basic-access

Click “Go to App”; you should be taken to a page that says “Success.” FBCMD still needs authorization to access your account offline. Run:

fbcmd go auth

When this page opens up in your default browser, click “Generate”:

social-fbcmd-go-auth

Facebook will then give you an authorization code, which you only need for one-time use. Copy the code and run:

fbcmd auth [code]

If all goes well, you’ll receive a friendly “Welcome to FBCMD” message in your terminal. Finally, grant FBCMD default permissions with:

fbcmd addperm

This will take you to yet another web page, where you must hit the “Allow” button. Now you can proceed to using FBCMD.

Usage

All FBCMD commands start with fbcmd, followed by an argument. Simply type fbcmd to view all the possible commands. Some examples include:

  • Update your status:
    fbcmd status "I'm totally updating my Facebook status from the command line!"
  • Read your messages:
    fbcmd inbox
  • Post on your friend Buddy Pal’s wall:
    fbcmd wallpost "Buddy Pal" "Wanna rage this Monday night?"
  • RSVP to an event:
    fbcmd rsvp [event_id] yes|no|maybe

Look no further than the Perl program TTYtter for your command-line Twitter experience. TTytter even supports the StatusNet and Identi.ca APIs in addition to Twitter.

social-ttytter-replies

Installation

Prereqisites include Perl 5.8.6 or newer and either Lynx or cURL. As of the day I’m writing this article, the latest stable version of TTYtter is 2.0.4 (from October 4, 2012). I recommend downloading the public beta (2.1) instead, as it is compatible with the latest changes in Twitter’s API. To get the beta, cd into your desired installation directory and run:

wget http://www.floodgap.com/software/ttytter/beta/beta.txt
mv beta.txt ttytter
chmod +x ttytter
./ttytter

The authorization wizard will start in your terminal. Following the wizard’s instructions, visit the authorization page in your browser.

social-ttytter-auth

Generate the PIN and enter it in your terminal following the prompt. By default, the keyfile will be saved as “.ttytterkey” in your home directory.

Usage

If you installed TTYtter in a system directory such as /usr/bin, you can run it simply by typing ttytter. Otherwise, you’ll have to either specify the full path of the executable when you run it or add its directory to your $PATH environment variable. If your terminal supports ANSI colors, start TTYtter with ttytter -ansi.

The ttytter command lists recent posts from the users you follow and then opens an interactive session. At the prompt, you can type /help to list commands or /quit to exit. Here are some basic commands:

  • Make a status update by simply typing it into the prompt:
    I'm tweeting from my headless server!
  • Refresh to see the newest tweets from the users you follow:
    /refresh
  • Display a user’s profile information:
    whois [username]
  • View your replies and mentions:
    /replies
  • Search Twitter:
    /search [term]

For more TTYtter commands and information about scripting TTYtter, see the official documentation. Happy tweeting!

Hungry for more ways to use the command line for social media? Stay tuned for Part 2!

Do you like what you read here?

Receive the latest update in your inbox.

Or connect with us: