PHP FriendFeed API v.2 using OAuth method

FriendFeed is an interesting amalgamation of social media and bookmarking site by which users can share links, photos and videos and converse about the post with their friends.

FriendFeed has upgraded its API recently to make it simpler to use and added some new features. FriendFeed has switched from CURL authentication to OAuth authentication. OAuth makes the user experience simpler and more secure. FriendFeed supports the OAuth Core 2.0 standard.

Following are the steps to connect with FriendFeed using OAuth:

1] Create your account on FriendFeed (http://friendfeed.com)

2] Register your application using the following link:
http://friendfeed.com/api/register

3] After the registration of your application you can manage it using:
http://friendfeed.com/api/applications
(Specify proper callback urls)

4] Get your secret keys from “manage application”.

5] FriendFeed OAuth API library needs to be included to avail to the FriendFeed operations like post and view feeds. You can download the FriendFeed library by clicking on the link at the bottom of this post.

6] Create the OAuth URL using following code:

$ff = new Friendfeed($consumer_key ,$consumer_key_secret); $tokens = $ff->fetch_oauth_request_token();
$request_token = $tokens["oauth_token"]; 
$oauth_token_secret = $tokens["oauth_token_secret"]; /// Save the response in session for further use. $_SESSION["ff_oauth_token_secret"] =  $oauth_token_secret; $_SESSION["'ff_oauth_token"] =  $request_token; 
$auth_url = $ff->get_oauth_authentication_url($tokens); 
echo '<a href="'.$auth_url.'">Login to frienfeed </a><br>';

7] After successful authentication, FriendFeed redirects you to the callback url specified while creating the application. You need to save the tokens in the database that are provided to you in the URL. The code is as follows:

$oauth_token = $_GET['oauth_token'];  // Provided you in URL $_SESSION["ff_oauth_token_secret"] =  $oauth_token_secret; //  Retrive ff_oauth_token_secret from session stored in step 6. $ff = new Friendfeed($consumer_key ,$consumer_key_secret); # Get access token $arr = array('oauth_token' => $oauth_token,'oauth_token_secret' => $oauth_token_secret); $db_tokens = $ff->fetch_oauth_access_token($arr);  // Save the tokens in $db_tokens in database for further use.

8] Fetch FriendFeed profile using the following URL:

$Ff = new FriendFeed($consumer_key, $consumer_key_secret, array ('oauth_token' => $db_tokens['oauth_token'], 'oauth_token_secret' => $db_tokens['oauth_token_secret'])); $resp = $Ff->fetch_feed('me', array ('num' => 500)); print_r($resp)         // Prints your profile.

9] Use the following code to update the status:

$ff = new Friendfeed($consumer_key ,$consumer_key_secret); $Ff = new FriendFeed($consumer_key, $consumer_key_secret, array ('oauth_token' => $rowList['access_token'], 'oauth_token_secret' => $rowList['access_token_secret'])); $Feed = $Ff->post_entry($bookmark_title,$bookmark_url,'me'); print_r( $Feed) // Check the response to validate status is updated successfully.

The API requires OAuth library to execute OAuth related operations; you can click here to download OAuth library and FriendFeed library.

This entry was posted in API, Programming and tagged , , , . Bookmark the permalink.

Leave a Reply