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.
As a prerequisite, you need to install command line interface for PHP.
On Debian, Ubuntu:
On Fedora, CentOS or RHEL:
After installation, verify that PHP5 is installed with curl support.
/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.
To prepare the installation of fbcmd, run the command:
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).
$ 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.
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".
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.
To post a message on your wall:
To post a message on peter's wall:
To list current status of your friends:
To list any friends who are currently online:
To see the stream stories for your friends:
To comment on a story #5 found in your friend' stream:
To like a story #3 that appears in your friend' stream:
For a full list of commands, refer to the official documentation.
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:
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.