Monday, September 28, 2009

Facebook PHP Application Fun

I don't like having multiple files when I can get away with only having one. The Facebook API requires multiple files (3 Facebook and 3 JSON for PHP versions older than 5.2). I decided to merge them into one. A simple call to cat to merge all files wasn't going to work due to the way they were set up, so I did it manually. The resulting beast is posted at http://pastebin.com/f316e87b7. (I call the file .libfb.php)

Dave Tomkins wrote the FBCMD Facebook application using their API. I just wanted to update my Facebook status from the command-line so for the most part his application seemed like bloat to me. So I stripped that down too and decided to have it include the single file I created. The stripped down version is posted at http://pastebin.com/f1136246d.

Note: My stripped script depends on you properly installing his application via Facebook, using the fbcmd.php AUTH command to generate the sessionkeys.txt file and sticking the values from that text file into the stripped down script. After that, you can delete the full version and just use the stripped down script.

Basic installation and usage is as follows:


$ mkdir ~/.fbstat && cd ~/.fbstat
$ wget -O .libfb.php 'http://pastebin.com/pastebin.php?dl=f316e87b7'
$ wget -O fbstat 'http://pastebin.com/pastebin.php?dl=f1136246d'
$ chmod +x fbstat
$ ./fbstat "decided to use a stripped down version of FBCMD"
$ echo $PATH:`pwd` >> ~/.bashrc


If you have a ~/bin, ~/.bin, etc. then you may wish to download there. You may need to edit line 1 of the fbstat file to match the path to PHP on your system (which php/code>).

Edit: Yes, if you want, you can concatenate the two scripts (.libfb.php and fbstat) into a single script and use it that way.

$ cat .libfb.php fbstat > fb.php && rm -f .libfb.php fbstat && mv fb.php fbstat