Getting started with the FriendFeed API and PHP

by Sherif

FriendFeed is cool.

What is FriendFeed?
If you haven’t signed up yet you should – its basically an feed aggregation for a lot of services (Eg Twitter, YoutTube, GoogleReader, Last.fm… and many many many other services). It lets you consolidate all your activity in all the third-party services into one feed. People have termed it as ‘twitter’ on steroids. The thing I like the most about it is I can go to one place, and find out what my friends are doing on all their social network services. The guys that developed FriendFeed are ex-Googlers, and have got big plans for it. Read more about FriendFeed here.

FriendFeed API
The FriendFeed API is a RESTfull API. The RESTfull API is available in four main formats JSON, XML, Atom 1.0 and RSS 2.0. The full FriendFeed API specification can be found on the FriendFeed Google Code page and is all opensourced.

Tutorial with FriendFeed API and PHP
So I’ve been playing around with the FriendFeed API in PHP. In the examples below I am retrieving all data in JSON format, and then parsing it in PHP. So here is some very basic sample code to get you started:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
include("friendfeed.php");
include("JSON.php");
 
//Connect
$friendfeed = new FriendFeed("yourusername", "yourpassword");
 
//Sample code to post data via the API
$entry = $friendfeed->publish_message("Testing the FriendFeed API");
 
//Sample PHP code to get data for a specific users feed via the FriendFeed API
//The below gets the first 30 entries in that users feed
$feed = $friendfeed->fetch_user_feed("some_random_user_name", 0, 0, 30);
foreach ($feed->entries as $entry) {
  //get the image of the service, and its name (eg twitter, googlereader...)
  $output .= '<img src="' . $entry->service->iconUrl . '" alt="' . $entry->service->name . '" />';
 
  //get the title of the entry and link to it
  $output .= $entry->service->name.'<a href="'.$entry->link.'">'.$entry->title.'</a>';
 
  //get the date of the entry
  $output .= date('Y m d', $entry->published);
 
}
 
echo $output; //prints the entry title, icon and link to the entry
 
//TODO: Continue to write an awesome FriendFeed Application with PHP

The above code should be enough to get you started. Be sure to put in error checks etc when writing your FriendFeed application! To find out what other services are available, check out the FriendFeed API doco.

Final Result
What to see what It could look like? Check out my final result here. It’s a Mashup between FriendFeed and the Google Charts API.

Have Fun! and see you on my FriendFeed.