<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Made of Everything You&#039;re Not &#187; friendfeed</title>
	<atom:link href="http://blog.ericlamb.net/tag/friendfeed/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Thu, 27 Oct 2011 01:29:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Using the FriendFeed API with PHP</title>
		<link>http://blog.ericlamb.net/2009/03/using-the-friendfeed-api-with-php/</link>
		<comments>http://blog.ericlamb.net/2009/03/using-the-friendfeed-api-with-php/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 13:12:39 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[friendfeed]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=911</guid>
		<description><![CDATA[Dissenting opinion: I don&#8217;t like social networking as a consumer. I just find the whole thing pretty stupid; meeting people online that I&#8217;ll never meet in real life, who I have only a vague similarity to,  makes me feel retarded. Facebook, MySpace, Twitter can all go to hell. Sorry, had to be said. (I&#8217;ll probably [...]]]></description>
			<content:encoded><![CDATA[<p>Dissenting opinion: I don&#8217;t like social networking as a consumer. I just find the whole thing pretty stupid; meeting people online that I&#8217;ll never meet in real life, who I have only a vague similarity to,  makes me feel retarded. Facebook, MySpace, Twitter can all go to hell. Sorry, had to be said. (I&#8217;ll probably be writing a post on this soon.)</p>
<div id="attachment_913" class="wp-caption aligncenter" style="width: 266px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/friend_feed_logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Ffriend_feed_logo.png','FriendFeed+Logo')"><img class="size-full wp-image-913" title="FriendFeed Logo" src="http://blog.ericlamb.net/wp-content/uploads/2009/03/friend_feed_logo.png" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Ffriend_feed_logo.png','FriendFeed+Logo')" alt="FriendFeed Logo" width="256" height="55" /></a><p class="wp-caption-text">FriendFeed Logo</p></div>
<p>I do love building them though. They&#8217;re a joy to work on because of the complexities involved and right now it&#8217;s prettty exciting because of all the new stuff coming out daily.</p>
<p>Anyway, for an upcoming project I needed to integrate the FriendFeed API into a website. This was painful because, as I said above, I hate social networking sites. I didn&#8217;t belong to too any at the time so I had to spend about an hour signing up with a few of the  social networks FriendFeed supports.</p>
<p>After that though, working with the API was pretty painless. To get started all you have to do is </p>
<ol>
<li><a href="https://friendfeed.com/account/create" onclick="return TrackClick('https%3A%2F%2Ffriendfeed.com%2Faccount%2Fcreate','Sign+up+with+FriendFeed')" target="_blank" title="Sign up with FriendFeed">Sign up with FriendFeed</a></li>
<li><a href="http://friendfeed.com/settings/services" onclick="return TrackClick('http%3A%2F%2Ffriendfeed.com%2Fsettings%2Fservices','Import+your+sites')" title="Import your sites" target="_blank">Import your sites</a></li>
<li><a href="http://friendfeed.com/remotekey" onclick="return TrackClick('http%3A%2F%2Ffriendfeed.com%2Fremotekey','Get+API+Key')" title="Get API Key" target="_blank">Get API Key</a></li>
<li><a href="http://code.google.com/p/friendfeed-api/" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fp%2Ffriendfeed-api%2F','Download+php+API+code')" title="Download php API code" target="_blank">Download php API code</a></li>
</ol>
<p>Try not to look too closely to the API code; there&#8217;s almost zero formatting. Just know it works. If you have php compiled with curl support that is; you HAVE to have curl support.</p>
<h3>API Calls</h3>
<p>Pull a user feed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_user_feed</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$nickname</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pull a user comment feed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_user_comments_feed</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pull a user likes feed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_user_likes_feed</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pull a user discussion feed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_user_discussion_feed</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pull a merged feed with all of the given users&#8217; entries. Note that authentication is required if any one of the users&#8217; feeds isn&#8217;t public and that $nicknames is an array of users:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_multi_user_feed</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$nicknames</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pull the entries the authenticated user sees on their home page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_home_feed</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Perform a search. The format for $query is the same as the <a href="http://friendfeed.com/search/advanced" onclick="return TrackClick('http%3A%2F%2Ffriendfeed.com%2Fsearch%2Fadvanced','FriendFeed+search')" title="FriendFeed search" target="_blank">FriendFeed search</a>. If you authenticate the request the search applies to the authenticated user. If it&#8217;s not authenticated the search is against all public feeds.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$service</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$start</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Publishes the provided link/title to the authenticated users page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// image_urls is a list of URLs that will be downloaded and included as</span>
<span style="color: #666666; font-style: italic;">// thumbnails beneath the link. The thumbnails will all link to the</span>
<span style="color: #666666; font-style: italic;">// destination link. If you would prefer that the images link somewhere</span>
<span style="color: #666666; font-style: italic;">// else, you can specify images instead, which should be an array of</span>
<span style="color: #666666; font-style: italic;">// name-associated arrays of the form array(&quot;url&quot;=&gt;...,&quot;link&quot;=&gt;...).</span>
<span style="color: #666666; font-style: italic;">// The thumbnail with the given url will link to the specified link.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// audio_urls is a list of MP3 URLs that will show up as a play</span>
<span style="color: #666666; font-style: italic;">// button beneath the link. You can optionally supply audio[]</span>
<span style="color: #666666; font-style: italic;">// instead, which should be a list of name-associated arrays of the </span>
<span style="color: #666666; font-style: italic;">// form (&quot;url&quot;=&gt; ..., &quot;title&quot;=&gt; ...). The given title will appear when</span>
<span style="color: #666666; font-style: italic;">// the audio file is played.</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// We return the parsed/published entry as returned from the server,</span>
<span style="color: #666666; font-style: italic;">// which includes the final thumbnail URLs as well as the ID for the</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publish_link</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image_urls</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$images</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$via</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$audio_urls</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$audio</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$room</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Add a comment to a users page; returns the comment_id</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_comment</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Edit a comment on a users page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">edit_comment</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Delete a comment:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete_comment</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_id</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Un-deletes a comment:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">undelete_comment</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$comment_id</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Add like for a given $entry_id:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_like</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Deletes a like for a give $entry_id:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$friendfeed</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FriendFeed<span style="color: #000;">&#40;</span><span style="color: #000088;">$friendfeed_nickname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$friendfeed_key</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$friendfeed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete_like</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$entry_id</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Further Reading</h3>
<p><a href="http://blog.sherifmansour.com/?p=218" onclick="return TrackClick('http%3A%2F%2Fblog.sherifmansour.com%2F%3Fp%3D218','Getting+started+with+the+FriendFeed+API+and+PHP')" title="Getting started with the FriendFeed API and PHP" target="_blank">Getting started with the FriendFeed API and PHP</a><br />
<a href="http://code.google.com/p/friendfeed-api/wiki/ApiDocumentation" onclick="return TrackClick('http%3A%2F%2Fcode.google.com%2Fp%2Ffriendfeed-api%2Fwiki%2FApiDocumentation','FriendFeed+API+Documentation')" title="FriendFeed API Documentation" target="_blank">FriendFeed API Documentation</a></p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2009/03/using-the-friendfeed-api-with-php/' addthis:title='Using the FriendFeed API with PHP '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/03/using-the-friendfeed-api-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shifting Requirements = Better Coder</title>
		<link>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/</link>
		<comments>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 14:00:51 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[friendfeed]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[relative time]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=971</guid>
		<description><![CDATA[So often in the development process shifting requirements can wreak havoc on the entire project. But sometimes, every once in a while, if the moon is in just the right place and the wind is blowing in the proper direction, you can walk away a better coder for it. Take for example my recent experience [...]]]></description>
			<content:encoded><![CDATA[<p>So often in the development process shifting requirements can wreak havoc on the entire project. But sometimes, every once in a while, if the moon is in just the right place and the wind is blowing in the proper direction, you can walk away a better coder for it.</p>
<div id="attachment_998" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/03/rhino.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F03%2Frhino.jpg','Rhino')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/03/rhino-300x199.jpg" alt="Rhino" title="Rhino" width="300" height="199" class="size-medium wp-image-998" /></a><p class="wp-caption-text">Rhino</p></div>
<p>Take for example my recent experience integrating the FriendFeed API into a client&#8217;s site.</p>
<h3>Pop Quiz</h3>
<p>The client has a website that utilizes the FriendFeed API, on the homepage only, to display information about their online activities. Basically, they want the site to be updated automatically whenever they update their MySpace or YouTube pages and the like. They&#8217;ve specified the layout to be something like the below:</p>
<p>&#8220;ClientName&#8221; just published a piece titled &#8220;Title&#8221; on &#8220;Site&#8221;. Published &#8220;X hours ago&#8221;</p>
<p>Pretty simple right? An obvious design would go something like this:<br />
1. Connect to FriendFeed API.<br />
2. Make request for data.<br />
3. Display on the page.</p>
<p>The only issue is the formatting of the date / time difference. No worries though; there&#8217;s php code all over the place for that:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> RelativeTime<span style="color: #000;">&#40;</span><span style="color: #000088;">$timestamp</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
	<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$timestamp</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$periods</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;sec&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;min&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;hour&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;day&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;week&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;month&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;decade&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$lengths</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;60&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;24&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;7&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;4.35&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;10&quot;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span> <span style="color: #666666; font-style: italic;">// this was in the past</span>
		<span style="color: #000088;">$ending</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span> <span style="color: #666666; font-style: italic;">// this was in the future</span>
		<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #000088;">$difference</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ending</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;to go&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">for</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$difference</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$lengths</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$j</span><span style="color: #339933;">++</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$difference</span> <span style="color: #339933;">/=</span> <span style="color: #000088;">$lengths</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$difference</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$difference</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$periods</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #000;">&#93;</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$difference</span> <span style="color: #006699; font-weight: bold;">$periods</span>[<span style="color: #006699; font-weight: bold;">$j</span>] <span style="color: #006699; font-weight: bold;">$ending</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Using the above you can just execute the output like the below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #22f;">echo</span> <span style="color: #000088;">$me</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' just published a piece titled '</span><span style="color: #339933;">.</span><span style="color: #000088;">$post_title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' on '</span><span style="color: #339933;">.</span><span style="color: #000088;">$site</span><span style="color: #339933;">;</span>
<span style="color: #22f;">echo</span> <span style="color: #0000ff;">' Published '</span><span style="color: #339933;">.</span>RelativeTime<span style="color: #000;">&#40;</span><span style="color: #000088;">$relative_time</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Feeling pretty proud of yourself you show it off to the Producer in charge of the program and they come back with, &#8220;Nice! But how will it hold up after caching is enabled?&#8221;.</p>
<p>Well, I hadn&#8217;t thought of that (my bad fully)&#8230;</p>
<h3>The Oh Shit Moment</h3>
<p>Turns out, they&#8217;re expecting a lot of traffic (or the website is pretty resource intensive; take your pick) so full page caching is going to be required.</p>
<p>The problem is the timestamp; since all output is going to be cached the generated time, &#8220;5 minutes ago&#8221; or &#8220;2 days ago&#8221;, etc, isn&#8217;t going to change until the cache expires. This is not good&#8230;</p>
<h3>How I Fixed This (The Wrong Way)</h3>
<p>The first thing I did was make the conclusion that if php couldn&#8217;t be used then the job of formatting the string is up to JavaScript. &#8220;OK&#8221;, I thought, &#8220;fine, I&#8217;ll just port the php function to JavaScript and go about my day.</p>
<p>Here&#8217;s what I came up with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> getUnixTimestamp<span style="color: #000;">&#40;</span>timeObj<span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span>timeObj <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #000;">&#40;</span>timeObj<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span>
		dateObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	<span style="color: #22f;">return</span> <span style="color: #000;">&#40;</span>parseInt<span style="color: #000;">&#40;</span>dateObj.<span style="color: #660066;">getTime</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>.<span style="color: #660066;">substring</span><span style="color: #000;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> RelativeTime<span style="color: #000;">&#40;</span>timestamp<span style="color: #000;">&#41;</span><span style="color: #000;">&#123;</span>
&nbsp;
	difference <span style="color: #339933;">=</span> getUnixTimestamp<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span> <span style="color: #339933;">-</span> timestamp<span style="color: #339933;">;</span>
	periodArr <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	periods <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;sec,min,hour,day,week,month,years,decade&quot;</span><span style="color: #339933;">;</span>
	periodArr <span style="color: #339933;">=</span> periods.<span style="color: #660066;">split</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	TimeLengths <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span>
	timelength <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;60,60,24,7,4.35,12,10&quot;</span><span style="color: #339933;">;</span>
	TimeLengths <span style="color: #339933;">=</span> timelength.<span style="color: #660066;">split</span><span style="color: #000;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span>difference <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span> <span style="color: #006600; font-style: italic;">// this was in the past</span>
		ending <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span> <span style="color: #22f;">else</span> <span style="color: #000;">&#123;</span> <span style="color: #006600; font-style: italic;">// this was in the future</span>
		difference <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> difference<span style="color: #339933;">;</span>
		ending <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;to go&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #22f;">for</span><span style="color: #000;">&#40;</span>j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> difference <span style="color: #339933;">&gt;=</span> TimeLengths<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		difference <span style="color: #339933;">/=</span> TimeLengths<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	difference <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #000;">&#40;</span>difference<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span>difference <span style="color: #339933;">!=</span> <span style="color: #CC0000;">1</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
	text <span style="color: #339933;">=</span> difference<span style="color: #339933;">+</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>periodArr<span style="color: #000;">&#91;</span>j<span style="color: #000;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>ending<span style="color: #339933;">;</span>
	document.<span style="color: #22f;">write</span><span style="color: #000;">&#40;</span>text<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000;">&#125;</span></pre></div></div>

<p>Feeling sure of myself, <em>again</em>, a thought occurs to me that this still doesn&#8217;t fix the issue 100%. Sure, the date format will be consistent with the relative requirement, but the feed won&#8217;t be updated in &#8220;Real Time&#8221; so the full requirement isn&#8217;t there.</p>
<h3>The Real Solution</h3>
<p>A better idea would be to use AJAX to populate the area of the site where the blurb will be displayed. Since the AJAX request is independent of the rest of the site caching won&#8217;t be an issue. Sure, it&#8217;s a little more complicated but by doing an AJAX call the client gets exactly what they want.</p>
<h3>The Lesson</h3>
<p>Now, I&#8217;m not going to go into detail about the AJAX solution, mostly because I haven&#8217;t written it yet <img src='http://blog.ericlamb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , but, to me, this is the far superior solution. </p>
<p>Admittedly, I was a little frustrated that I didn&#8217;t think of the AJAX solution sooner. That is, until I realized how much I had learned going in the &#8220;wrong&#8221; direction. </p>
<p>I had no idea that generating a UNIX timestamp in JavaScript was &#8220;complicated&#8221;.<br />
I learned a lot about JavaScript string handling.<br />
I got a quick primer in how JavaScript&#8217;s builtin Split function works.<br />
I got a little humility out of the process too.</p>
<p>Sometimes, it&#8217;s good to go astray on a project. </p>
<div><a class="addthis_button" href="http://blog.ericlamb.net//addthis.com/bookmark.php?v=250" addthis:url='http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/' addthis:title='Shifting Requirements = Better Coder '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/03/shifting-requirements-equals-better-coder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

