How to access Facebook from the command line on Linux

A today's Facebook page is composed of a mix of sophisticated dynamic content, constantly updated with your latest timeline, your friends' status updates, notifications, online chats, third-party advertisements tailored to your interest, and so on.

While this complex mashup may be a result of careful design choices made by Facebook, for us, accessing Facebook is no longer as lightweight as used to be. For example, don't be surprised if opening your Facebook page on web browser involves more than a dozen TCP connections to different end points (e.g., Facebook CDN, Akamai, third-party advertisers, etc).

If you know what you are doing on Facebook, you can consider a much lightweight alternative Facebook client called fbcmd, a command-line client for Facebook, instead of heavy-weight Facebook web access. Using fbcmd's command line interface (CLI), you can do pretty much everything you would do on Facebook, but without having to download superfluous dynamic content.

In this tutorial, I will cover how to access Facebook from the command line on Linux, by using fbcmd CLI.

Preparation

As a prerequisite, you need to install command line interface for PHP.

On Debian, Ubuntu:

$ sudo apt-get install php5-cli php5-curl

On Fedora, CentOS or RHEL:

$ sudo yum install php-cli

After installation, verify that PHP5 is installed with curl support.

$ php -r 'echo phpversion();'
5.5.7
$ php -r 'phpinfo();' | grep -i curl
/etc/php.d/curl.ini,
curl
cURL support => enabled
cURL Information => 7.32.0

Install fbcmd on Linux

First download fbcmd_update.php from its official source, which will be used to install fbcmd.

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

To prepare the installation of fbcmd, run the command:

$ php fbcmd_update.php

This will create ~/.fbcmd directory which contains a preferences file.

Now go ahead and run the following two commands, which will install fbcmd in the default installation location (e.g., /usr/local/lib, and /usr/local/bin).

$ sudo php fbcmd_update.php sudo
$ php fbcmd_update.php

Finally, make sure that /usr/local/bin is included in your PATH.

Configure fbcmd on Linux

One-time initial configuration for fbcmd proceeds in three steps.

Step 1: Grant fbcmd basic access to your Facebook account. For that, simply run fbcmd command as a non-root user.

$ fbcmd

This will print a Facebook URL as shown below. Copy and paste this URL on a web browser window.

After logging in to your Facebook account, you will see the following screen. Click on "Okay" to finalize basic access authorization.

Step 2: Get authorization code. You need to get an authorization code from Facebook to be able to access your Facebook account offline.

For this, go to http://www.facebook.com/code_gen.php?v=1.0&api_key=42463270450 on your web browser, and generate one-time AUTH code to use.

The AUTH code is time-sensitive, and can expire if not used right away. If the code expires, you can re-generate it.

Once an AUTH code is generated, run the following command, where "XXXXXX" is your AUTH code. You will see "AUTH code accepted".

$ fbcmd auth XXXXXX

Step 3: Grant additional permission to access and manage your Facebook account.

For this, go to this Facebook URL on your web browser, which will ask you to grant access permissions on various properties. Continue to click "Okay" button until you are done. Don't worry. This step will not allow any other user to access your Facebook account. All the granted permissions are linked to your Facebook account only.

This is the end of fbcmd configuration.

Basic Usage of fbcmd

To verify the permissions granted on fbcmd, run the following command, which will show you permission status.

$ fbcmd showperm

To post a message on your wall:

$ fbcmd post "Hello, world!"

To post a message on peter's wall:

$ fbcmd target peter post "Hello, Peter!"

To list current status of your friends:

$ fbcmd fstatus

To list any friends who are currently online:

$ fbcmd fonline

To see the stream stories for your friends:

$ fbcmd stream

To comment on a story #5 found in your friend' stream:

$ fbcmd comment 5 "This is funny"

To like a story #3 that appears in your friend' stream:

$ fbcmd like 3

For a full list of commands, refer to the official documentation.

Troubleshooting fbcmd

1. If you are getting the following timezone warning message from PHP, specify your timezone in php.ini file, which is located in /etc/php.ini (RedHat-based system) or /etc/php5/cli/php.int (Debian-based system).

PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /usr/local/lib/fbcmd/fbcmd.php on line 1207

For example, on Fedora:

$ sudo vi /etc/php.ini
date.timezone = "America/New_York"

For more detail on how to set the default timezone in PHP, refer to this tutorial.


Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

13 thoughts on “How to access Facebook from the command line on Linux

    • No, it simply means a particular access token can be used at most once. Once fbcmd is authorized by the access token, you can freely run fbcmd without any further authentication.

    • Well, ask FB :) There is always chance things may break if you are using unofficial third party apps. You just live with it, enjoying what it offers while it can.

  1. A Facebook command-line client written in PHP!? I can hardly imagine anything else I could care less about.

  2. I was under the impression that the eventual token through the auth process expired after 60days.

    so if I use fbcmd for a while, then I don't for four months I will need to reauthorize, correct?

Leave a comment

Your email address will not be published. Required fields are marked *

Current day month ye@r *