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.
hey,
(
thanks for the tutorial. I tried this to post the test message to my friend feed’s account, but it didnt work
Hey Annon, What didnt work? Did you make sure you you got the JSON.php lib and friendfeed.php libs?
It works fine for me…
Greetings from Singapore.. Was useful to implement http://www.nextbestaction.com/fft/ Thanks
[...] blogged about FriedFeed a while ago and how to get started writing your own app with the FriendFeed API, PHP and JSON, a lifestream aggregation [...]
Great article! I’ve got it working with public feeds but how do you fetch a LIST that requires authentication? HavenĀ“t seen any examples with PHP.
@Erik Assuming you have authenticated with your key:
…. new FriendFeed(“yourusername”, “yourpassword”);
…
You can then call the feed for people you have access to:
…
$feed = $friendfeed->fetch_user_feed(“some_random_user_name”, 0, 0, 30);
…
(Just change the random username)
[...] Getting started with the FriendFeed API and PHP FriendFeed API Documentation var addthis_pub = ‘mithra62′; var addthis_language = ‘en’;var addthis_options = ‘email, favorites, digg, delicious, myspace, google, facebook, reddit, live, more’; [...]
Thanks dude, that works…
thank you very much for the post! it is so useful.
[...] weeks a go I was having a chat to a friend about FriendFeed. I’m a big fan of FriendFeed (see some previous posts) and think it does a good job at helping you solve a problem of being able to manage [...]
Why not include the friendfeed.php and
JSON.php files in your demo, rather than just saying “include them” That doesn’t help us at all, you dick.