Tuesday, March 27, 2012

FBCMD: Command Line for Facebook


The Basics
There are a few prerequisites for installing the command line Facebook application,FBCMD. PHP 5.x is a requirement, since the application is a single PHP file. You can install php5 via any method you wish but, in my experience, I had to install php5-cli, php5-gd, and php5-mysql to use this application. Your experience and mileage may vary.
Connect to the FBCMD and download the PHP file or grab it easily via curl.
$ curl -O https://github.com/dtompkins/fbcmd/raw/master/fbcmd_update.php
And, run the following two commands to complete this very simple installation.
$ sudo php fbcmd_update.php sudo

fbcmd update utility [version 2.91]

http://fbcmd.dtompkins.com/update

php fbcmd_update.php install

fbcmd update utility [version 2.91]

http://fbcmd.dtompkins.com/update

.....................

Update: COMPLETE!

fbcmd version: [none] --> [1.0-beta5-dev1]

Note: fbcmd_update.php is now at [/usr/local/lib/fbcmd/fbcmd_update.php]
so you can remove the old one at [/home/khess/fbcmd_update.php]

type fbcmd to begin
As the prompt suggests, type fbcmd and see what happens.
$ fbcmd

Welcome to fbcmd! [version 1.0-beta5-dev1]

This application needs to be authorized to access your facebook account.

Step 1: Allow basic (initial) access to your acount via this url:

https://www.facebook.com/dialog/oauth?client_id=42463270450&redirect_uri=http://www.facebook.com/connect/login_success.html

to launch this page, execute: fbcmd go access

Step 2: Generate an offline authorization code at this url:

http://www.facebook.com/code_gen.php?v=1.0&api_key=42463270450

to launch this page, execute: fbcmd go auth

obtain your authorization code (XXXXXX) and then execute: fbcmd auth XXXXXX
These messages explain the steps you need to take next to grant FBCMD access to your Facebook information.
Making the Facebook Connection
Perform the following connections from a Linux desktop system because some of these commands use Firefox (or your default browser) to initiate the connections and setup the application. Open a Terminal and type in the following commands.
fbcmd go access
Your Internet browser will open to Facebook and prompt you for login. If you see a link that reads, “Login with Command Line” or something similar, select that link and login to Facebook. If you don’t see that link, login to Facebook the way you normally do. Return to your Terminal window and issue the following command:
$ fbcmd go access
This command prompts another connection to Facebook, where you should see a six character code that you’ll need for the next step.
fbcmd auth XXXXXX

fbcmd [v1.0-beta5-dev1] AUTH Code accepted.
Welcome to FBCMD, Kenneth Hess!

most FBCMD commands require additional permissions.
to grant default permissions, execute: fbcmd addperm
As instructed, issue the command in the message.
$ fbcmd addperm

launching: https://www.facebook.com/dialog/oauth?client_id=42463270450&redirect_uri=http://www.facebook.com/connect/login_success.html&scope=create_event,friends_about_me,friends_activities,friends_birthday,friends_checkins,friends_education_history,friends_events,friends_groups,friends_hometown,friends_interests,friends_likes,friends_location,friends_notes,friends_online_presence,friends_photo_video_tags,friends_photos,friends_relationship_details,friends_relationships,friends_religion_politics,friends_status,friends_videos,friends_website,friends_work_history,manage_friendlists,manage_pages,offline_access,publish_checkins,publish_stream,read_friendlists,read_mailbox,read_requests,read_stream,rsvp_event,user_about_me,user_activities,user_birthday,user_checkins,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationship_details,user_relationships,user_religion_politics,user_status,user_videos,user_website,user_work_history
Your FBCMD to Facebook connection is now complete and you’re ready to use FBCMD. To test that assertion, try the following command to see the permissions you granted the application.
$ fbcmd showperm
PERMISSION                    GRANTED?
ads_management                0
create_event                  1
email                         0
friends_about_me              1
friends_activities            1
friends_birthday              1
friends_checkins              1
friends_education_history     1
friends_events                1
friends_groups                1
...
user_videos                   1
user_website                  1
user_work_history             1
xmpp_login                    0
A ’1′ means permission granted and a ’0′ means permission denied. You can change permissions at any time by issuing the addperm keyword and a permission. See the FBCMDCommand Documentation for a complete listing of command keywords and syntax.
Using FBCMD
I can’t show you all of the FBCMD commands but I can show you a few of the fun ones. You can do almost anything with the command line interface that you can with the web interface. Your results may vary but generally speaking everything works pretty well. To see a list of your friends who are signed into Facebook, use fonline.
$ fbcmd fonline

NAME   ONLINE_PRESENCE
Friend One  idle
Friend Two  idle
Friend Three         idle
Friend Four  idle
Friend Five  active
Friend Six  active
Friend Seven         active
To see a list of messages that your friends have posted to your wall, use mywall.
$ fbcmd mywall
[#]  NAME          MESSAGE

[1]  Friend One  Hi , Hope you are good
You can read your Facebook messages with the inbox keyword.
$ fbcmd inbox
[#]   FIELD     VALUE

[1]   subject   [Hello]
      :to/from  Friend Four
      :snippet  Hi, what's up?
To check those annoying event invitations that people send you, use events.
$ fbcmd events
[#]  START_TIME        RSVP         EVENT
[1]  Wed May 25 02:00  not_replied  Towel Day - Celebrating Douglas Adams
[2]  Sat Jul 16 10:00  declined     William Bernhardt Small-Group Seminar
         (Level 3)
And, last but not least, you can update your status. You wouldn’t want anyone to miss any aspect of your fascinating existence or your latest video game scores.
$ fbcmd post "This is a test post from FBCMD"
POST_ID
1443542993_205008538849
If you’re a PHP programmer, I suggest that you expand and extend this application by contacting the primary developer. See the Contribute page for more information.
For those of you who love to use Facebook, you’re sure to love an easy to install, easy to use command line Facebook application like FBCMDFBCMD has a lot of potential as an evolving command line application that I hope someone incorporates into a repository so that it’s even easier to install for those who don’t like to install applications. Those of us who like a challenge are in the minority. Most people just want something that works and works without hassle or strain. Make it so, Linux fans.