Make Adium show your Facebook status

by Dave Dash 03Feb07

By using a simple RSS feed, you can have Adium report your Facebook status.

I am a late-adopter to social networks. I participated in LiveJournal years after many of my friends started using it. I finally got into Facebook months after it was "openned up." I like this strategy because I can immediately find my friends on the network and add them and amass 100s in a few short days.

Facebook is nice for its simple and clean interface. Even the features are fairly simple. I like the status feature... for no good reason. It's a simple AJAX status update that updates your status on the site. What I don't like to do is repeat myself. I wanted Adium to repeat what Facebook said.

My first inkling was to use the Facebook API, but that seemed less appealing since it would involve authentication. I almost gave up and then discovered that in Facebook you can go to "My Profile" and under "Status" go to "See All" and there's an RSS link to your status messages. Awesome. All I needed to do is grab the first one.

I decided this looked like a task for Simple XML which can take an XML string and turn it into a PHP object.

The first step of course was to fetch the RSS feed into a string. file_get_contents made the most sense, but Facebook does a browser check even for getting RSS feeds. I'm not fond of browser sniffing, but its easy to work around if you use cURL.

Excellent... this does exactly what I want - but it's slow. Like any good script, we should use caching if it makes sense. Obviously we don't want to overload the servers at Facebook (or for that matter any place that serves up RSS feeds) so we implement PEAR's Cache_Lite package. We'll tell it to cache results for 15 minutes. The code changes are marked with //+++ at the end of each new line:

That's it on the PHP side. On the Adium side you'll need to use the exec AdiumXtra. It'll allow you to set your status to something like:

/exec {/usr/local/php5/bin/php /usr/local/bin/facebook.php}

Enjoy.


Where am I?

This is a single entry in the weblog.

"Make Adium show your Facebook status" is filed under programming. It was published in February 2007.

February 2007
M T W T F S S
« Nov   Mar »
 1234
567891011
12131415161718
19202122232425
262728  

Tags

&& && && &&

need more help

If you found our tutorials and articles to be useful, but are still looking for more hands on help, consider hiring us. Find out more about how Spindrop can help you.

 

6 Responses to “Make Adium show your Facebook status”


  1. 1 abhi Posted May 27th, 2007 - 4:21 pm

    i cant find the feed under the ’status’. all the mini-feed see-all page does is create a page on the fly, theres no rss feed there to be imported elsewhere.

  2. 2 Paul Posted April 7th, 2008 - 2:39 pm

    This doesn’t work. I tested the exec xtra and tested the rss feed, and they both work. But the script outputs the following. What the hell is going on?

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}

    <?php

    require_once(’Cache/Lite.php’); //   </p>
    
    </p>
    
    $url = “http://www.facebook.com/feeds/status.php?id=517174511&amp;viewer=517174511&amp;key=761717bf90&amp;format=rss20”;</p>
    

    $options = array(’cacheDir’ =&gt; ‘/tmp/’, ‘lifeTime’ =&gt; 600); //   </p>
    

    $Cache_Lite = new Cache_Lite($options); //   </p>
    

    $data = null; //   </p>
    
    // attempt to load the data from cache,  //   </p>
    
    // otherwise load it anew from RSS //   </p>
    
    if (!($data = $Cache_Lite-&gt;get($id))) { //   </p>
    
    // setup curl</p>
    
        $ch = curl_init();</p>
    
        curl_setopt ($ch, CURLOPT_URL, $url);</p>
    
        curl_setopt ($ch, CURLOPT_HEADER, 0);</p>
    

        //spoof Firefox</p>
    
        curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.1) Gecko/20061223 Firefox/2.0.0.1″);</p>
    

        // begin output buffering</p>
    
        ob_start();</p>
    
        curl_exec ($ch);</p>
    
        curl_close ($ch);</p>
    
        // save buffer to string</p>
    
        $xmlstr = ob_get_contents();</p>
    

        ob_end_clean();</p>
    

        // convert string to xml object</p>
    
        $xml = new SimpleXMLElement($xmlstr);</p>
    

        // status messages start with ‘Dave is…’ </p>
    
        // I just want everything after my name</p>
    
        $data = str_replace(’Paul ‘, null,$xml-&gt;channel-&gt;item-&gt;title); //    </p>
    

        $Cache_Lite-&gt;save($data); //   </p>
    

    } //   </p>
    

    echo $data; //   </p>
    
    </p>
    

  3. 3 Dave Dash Posted April 7th, 2008 - 2:55 pm

    I admittedly don’t use this script anymore, but it looks like your PHP isn’t being interpreted before it’s being sent by the browser.

    For the record, I use twitterific to update twitter, adium and facbeook.

Who's linking?

  1. 1 Twitterbook: Update Twitter using Facebook Status | Design Meme Pingback on Mar 22nd, 2007
    "[...] I still didn’t want to manage two different “status” accounts, and I thought: “Maybe someone wrote a script that ... "
  2. 2 Drive Through… » Federated status Pingback on May 20th, 2007
    "[...] solutions to the problem (e.g. Twitterbook which updates Twitter with your Facebook status, and a PHP script to allow ... "
  3. 3 bonq.net/flipp » Blog Archive » daily del.icio.us Pingback on Dec 21st, 2007
    "[...] Adium show your Facebook status at Spindrop #tags: networking tools rss adium feeds mashup code php scripting [...] "

Further Help

If you require more hands on assistance, we do offer affordable hands on support.

Leave a Reply


Comment guidelines: No spamming, no profanity, and no flaming. Inappropriate comments will be deleted outright.