Why and How to access Facebook from the command line
Please read the notice at the end!!! You may have already noticed that, while I surely do not refuse graphical interfaces and cool, modern Linux desktop environments, I am always looking for ways to perform every computer-related task from the command line. Sometimes it is because I actually need to automate something. In other cases it is just for the fun of it, to discover if it’s possible. This is the case of the trick I am going to explain this week: how to post to one’s Facebook wall, or read it, from a script.
Of course, you may be wondering why a Free Software / Digital Rights supporter may want to do something like this. In my opinion, there are both general reasons and real world situations why knowing such a trick would be useful.
Facebook may be evil, the greatest attack to privacy ever invented, and so on, but that’s not the point (not here, anyway). Whatever one may think of Facebook, having a presence there is unavoidable these days, if you need to reach the many people who only go online to use Facebook. Wouldn’t it be very convenient, for example, to announce automatically on Facebook new releases of some Free Software application? Here’s how to do it.
Enter fbcmd
Dave Tompkins has written a little nice command line Facebook interface called fbcmd, that you may use as basis for your own application. Here I’ll only show how to set it up for the simplest, but also most useful task, that is posting a short status update to your wall.
To being with, install php on your computer if it isn’t there already, then download the fb_cmd_update.php script. The first time you’ll execute that script with the PHP interpreter:
[marco@facebook_cmd]# php fbcmd_update.php
it will greet you by listing the default configuration settings and explaining how to change them, if necessary. Once you’ve done that, you’ll have to type:
With this operation you will install, the actual PHP script that talks to Facebook, called fbmcd.php, and its shell wrapper, that is the command (fbcmd) that you will actually run. However, these files will still be unable to talk with Facebook.
You’ll have to explicitly log in to Facebook and authorize fb_cmd to post to your wall.
Authorizing the script to access your account
If you run fbcmd before it has loaded the right authorization code from Facebook, it will ask you to run a couple of extra commands:
Step 1: Allow basic (initial) access to your account via [a Facebook URL].
To launch this page, execute: fbcmd go access
Step 2: Generate an offline authorization code at [another Facebook URL].
To launch this page, execute: fbcmd go auth
In practice, it is not necessary to do so. You may go to the fb_cmd installation page and click on the link given in the “Basic Access” paragraph. This action will make Facebook ask your permission to give fb_cmd “basic access” to your account:

The next step would be to get from Facebook access credentials that fb_cmd can use to work on your account all by itself. This is a simple two-step procedure: first,click on the link given in the “Authorization Code” section of the installation page. Next, pass to the script the authorization code that Facebook returned in this way:
fbcmd auth AUTHCODE
Please note that, if you plan to have several Facebook users using the script, you will have to repeat this procedure for each of them! By default, fbcmd saves all the user-specific configuration and session data in the folder $HOME/.fbcmd. You can tell the software to use another folder by writing its path in the environment variable FBCMD.
How to authorize status updates
The steps described so far don’t accomplish much, in practice. If you want fbcmd to do something useful, you need to perform extra authorization steps.
This is something for which I have found the documentation on the website and the help message given by the script a bit confusing, or maybe not really up to date.
For example, in spite of what the script itself told me to do, eventually I found that the easiest way to set up automatic status updates, was to just go to the fb_cmd troubleshooting page and click on the link provided to “grant FBCMD the PUBLISH_STREAM permissions”.
By doing so, you will open a Facebook form as in the figure below, and all you’ll have to do will be to click on “Allow Publishing”.

Post to your Facebook wall with fbcmd
If there were no errors in the steps above, at this point fbcmd will be ready to post. As you can see below, I typed:

fbcmd post "Here is my first Facebook ^Catus update from the command line"
and a few seconds later the status update appeared in my Facebook wall, spelling error included. Of course, the same thing could (and should, since this is one of the main reasons to use fbcmd) be done inside a shell script!
Last but not least: back up your Facebook Data!
Fbcmd can do [much, much more than posting status updates http://fbcmd.dtompkins.com/commands]: thanks, Dave! Right now, I don’t plan to ever use any of those other functions, with one exception, which I strongly advise all of you to follow: back up on your computer all your status updates and posts from your friends. Fbcmd provides two commands for this very purpose, that is making complete or incremental backups of your Facebook wall. Set up a cron job to run them periodically, as I am going to do as soon as I finish writing this post, and you’ll always have your own copy of your Facebook activity.
IMPORTANT NOTICE
I wrote this short tutorial in February 2012 for TechRepublic, but they took it offline (why? Beats me) a few years later. On May 17th, 2025, I put it back online here because I needed it to be visible as a reference for this story of online abuses by Big Tech.
Who writes this, why, and how to help
I am Marco Fioretti, tech writer and aspiring polymath doing human-digital research and popularization.
I do it because YOUR civil rights and the quality of YOUR life depend every year more on how software is used AROUND you.
To this end, I have already shared more than a million words on this blog, without any paywall or user tracking, and am sharing the next million through a newsletter, also without any paywall.
The more direct support I get, the more I can continue to inform for free parents, teachers, decision makers, and everybody else who should know more stuff like this. You can support me with paid subscriptions to my newsletter, donations via PayPal (mfioretti@nexaima.net) or LiberaPay, or in any of the other ways listed here.THANKS for your support!