<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/chat/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/chat"/>
 <updated>2012-04-07T22:42:44-07:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>Make Adium show your Facebook status</title>
   <link href="http://davedash.com/2007/02/03/make-adium-show-your-facebook-status/"/>
   <updated>2007-02-03T00:00:00-08:00</updated>
   <id>http://davedash.com/2007/02/03/make-adium-show-your-facebook-status</id>
   <content type="html">&lt;p&gt;By using a simple &lt;acronym title=&quot;Really Simple Syndication&quot;&gt;RSS&lt;/acronym&gt; feed, you can have Adium report your Facebook status.&lt;/p&gt;

&lt;p&gt;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 &quot;openned up.&quot;  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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;!-- more --&gt;


&lt;p&gt;My first inkling was to use the Facebook &lt;acronym title=&quot;Application Programming Interface&quot;&gt;API&lt;/acronym&gt;, but that seemed less appealing since it would involve authentication.  I almost gave up and then discovered that in Facebook you can go to &quot;My Profile&quot; and under &quot;Status&quot; go to &quot;See All&quot; and there's an RSS link to your status messages.  Awesome.  All I needed to do is grab the first one.&lt;/p&gt;

&lt;p&gt;I decided this looked like a task for &lt;a href=&quot;http://us3.php.net/simplexml/&quot;&gt;Simple XML&lt;/a&gt; which can take an XML string and turn it into a PHP object.&lt;/p&gt;

&lt;p&gt;The first step of course was to fetch the &lt;acronym title=&quot;Really Simple Syndication&quot;&gt;RSS&lt;/acronym&gt; feed into a string.  &lt;code&gt;file_get_contents&lt;/code&gt; 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 &lt;a href=&quot;http://www.php.net/curl&quot;&gt;cURL&lt;/a&gt;.&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;php&quot;&gt;
&amp;lt;?php
    $url = &quot;http://mynework.facebook.com/feeds/status.php?replace=with&amp;your=own&amp;feed=url&quot;;

    // setup curl
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);

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

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

    ob_end_clean();

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

    // status messages start with 'Dave is...' 
    // I just want everything after my name
    echo str_replace('Dave ', null,$xml-&gt;channel-&gt;item-&gt;title);

&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;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 &lt;acronym title=&quot;Real Simple Syndication&quot;&gt;RSS&lt;/acronym&gt; feeds) so we implement &lt;acronym title=&quot;PHP Extension and Application Repository&quot;&gt;PEAR&lt;/acronym&gt;'s &lt;a href=&quot;http://pear.php.net/package/Cache_Lite&quot;&gt;Cache_Lite&lt;/a&gt; package.  We'll tell it to cache results for 15 minutes.  The code changes are marked with &lt;code&gt;//+++&lt;/code&gt; at the end of each new line:&lt;/p&gt;

&lt;div&gt;&lt;textarea name=&quot;code&quot; class=&quot;php&quot;&gt;
&amp;lt;?php

    require_once('Cache/Lite.php'); //+++
    
    $url = &quot;http://mynework.facebook.com/feeds/status.php?replace=with&amp;your=own&amp;feed=url&quot;;

    $options = array('cacheDir' =&gt; '/tmp/', 'lifeTime' =&gt; 600); //+++

    $Cache_Lite = new Cache_Lite($options); //+++

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

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

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

        ob_end_clean();

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

        // status messages start with 'Dave is...' 
        // I just want everything after my name
        $data = str_replace('Dave ', null,$xml-&gt;channel-&gt;item-&gt;title); // +++

        $Cache_Lite-&gt;save($data); //+++

    } //+++

    echo $data; //+++
    
&lt;/textarea&gt;&lt;/div&gt;


&lt;p&gt;That's it on the PHP side.  On the Adium side you'll need to use the &lt;a href=&quot;http://www.adiumxtras.com/index.php?a=xtras&amp;amp;xtra_id=1255&quot;&gt;exec AdiumXtra&lt;/a&gt;.  It'll allow you to set your status to something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/exec {/usr/local/php5/bin/php /usr/local/bin/facebook.php}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;
</content>
 </entry>
 

</feed>

