Feb 022013
 

In the past I’ve presented some clients for twitter that run on linux terminal, such as twidge and turses , they are really useful not just for connecting to social websites via your terminal but also to do scheduled jobs or procedure that will print a result or a message on these websites.

Fbcmd is a command line interface (CLI) for facebook.
It is open source and is both “free as speech” and “free as in beer”. It works in Windows, Mac and Linux.

Let’s see how you can use it.



Installation

Fbcmd is a single PHP file so you need to install php-cli and the php curl extension to use it.

On Debiam, Ubuntu and Mint you can install the requisites with the command

sudo apt-get install php5-cli php5-curl

This will install the latest php available on your linux box, now you should verify the php configuration, run these command from a terminal:

php -r "echo ini_get('allow_url_fopen');"
php -r "echo function_exists('curl_init');"
php -r "echo function_exists('json_decode');"

And make sure that each of them give as output “1″, if you see a 0 check the troubleshooting area of the official website.

Now get the latest version of this script with the command:

curl -O https://raw.github.com/dtompkins/fbcmd/master/fbcmd_update.php

or if this don’t works for you, download it from this direct link.

php fbcmd_update.php

It should display all of the installation settings, including where it will install, like this:

fbcmd update utility [version 3.0]
http://fbcmd.dtompkins.com/update
 
Preference file:                 [/linuxaria/.fbcmd/prefs.php]
 
Software development branch:     [master]
Software library destination:    [/usr/local/lib/fbcmd/]
Copy script to bin dir?:         [Yes]
Bin dir location:                [/usr/local/bin/]
Script name:                     [fbcmd]
Auto-restart when necessary:     [Yes]
 
Welcome!  This appears to be the first time running fbcmd_update.
 
To change any of the above settings, modify your preferences file
To change your preferences file location, set an FBCMD environment var.
 
Otherwise, The above default settings are fine for most users
 
To finish the installation:
 
   $ sudo php fbcmd_update.php sudo
   $ php fbcmd_update.php

You can customize these settings by modifying your preference file located in your home directory .fbcmd/prefs.php.
Note that it will install the software (library) to one location (eg: /usr/local/lib/fbcmd), and then add a script to another location (eg: /usr/local/bin) which should be in your path.

To complete the installation type the 2 commands that have been printed and now you can start it with fbcmd you’ll see an output that tells you that you have to enable facebook authentication, this is done in 2 steps:

Step One: Grant Basic Access

Before you can obtain an authorization code, you need to grant FBCMD basic access to your Facebook account, for this just type in a terminal:

fbcmd go access

Or visit this website to grant basic access.

Step Two: Obtain & Enter Authorization Code

After you’ve allowed basic access, you need to grant FBCMD authorization to use your Facebook account in offline mode.
This authorization is performed only once at installation: FBCMD stores your authentication information in your data directory for future use.
Type in the terminal:

fbcmd go auth

which should take you to this website to get an AUTH code (call it XXXXXX)
Now run the command:

fbcmd auth XXXXXX

and you should hopefully get a success message.
Note: AUTH codes are time-sensitive and can only be used once. If one fails, visit the website and generate another

Step Three: Obtain Additional Authorization

To execute most commands in FBCMD, you need to grant additional permissions, to grant FBCMD the default permissions, type:

fbcmd addperm

Final installation note:

You can install fbcmd on a Linux system where you don’t have sudo access; all you need to do is edit two settings in prefs.php before running fbcmd_update.php. install_lib_dir can be any directory you have write access to
install_bin_dir needs to be on your path, so $HOME/bin/ should work.

Basic usage of fbcmd

To see all the available options, you can type fbcmd in a terminal or visit the commands page of the website, these are some examples:

Update your status

fbcmd status "Hello, I'm updating FB from my cool terminal"

You can post an image

fbcmd POST IMG "check out this photo!" "http://example.com/image.jpg" "http://example.com/link.html"

You can post an image without a message or image link:

fbcmd POST IMG 0 "http://example.com/image.jpg" 0

If you have a Facebook page you can also post on it with:

fbcmd PPOST pagename "is changing the page status with the PPOST command"

you can also post images or other fancy stuff

fbcmd PPOST 1234567 IMG 0 "http://example.com/image.jpg" 0

Or just display your Facebook stream:

fbcmd stream

Conclusions

fbcmd can be a tool really useful if you manage facebook pages and want to plan ahead the posting of links or news, or just if you want to connect to your FB account from the terminal.

Popular Posts:

flattr this!

  6 Responses to “fbcmd : Manage facebook from the Linux terminal”

  1. Oh, I made something similar recently.

    Demo site is here. (You can try this in your web browser right now)
    http://kissrobber.github.io/facebook_client_terminal/
    Note: Only REPL mode is available in demo

    Please refer to the “Practical command example” section here
    https://github.com/kissrobber/facebook_client_terminal
    Many things are going to be done by using some commands in combination with pipe, grep and awk.
    In fact, this is far more useful than I thought before making this.

  2. very nice utility. I installed it and plaid with. I managed to make posts on my wall, on my pages and on friends walls. I wonder now if this little charm can be installed on my webhosting provider so I can cron some jobs

  3. This little php that uses fbcmd using shell_ecec will also post an article in the wall with image title text and url.
    $postresult = shell_exec(“/usr/local/bin/fbcmd PPOST $fbPageCode IMG 0 $urlimg $url ‘$title’ $url ‘$descr’ \n\r”);

  4. Hi,

    Updating from terminal is awesome …. How can we search something in the search bar and store the results in a file ?

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>