Get the Delicious Stumble And LinkedIn Shares Count Using PHP

Just Like our other tutorials, We will get the share counts of the Delicious, StumbleUpon and LinkedIn using PHP. We can get the data using their APIs and we can do that by using PHP and JSON.

Here are the APIs:

STUMBLEUPON:

http://www.stumbleupon.com/services/1.01/badge.getinfo?url=URL

LINKEDIN:

http://www.linkedin.com/countserv/count/share?url=URL&format=json

DELICIOUS:

http://feeds.delicious.com/v2/json/urlinfo/data?url=URL

Using these APIs we send them the URL to make a request, then they process it and give us the result, from the API site,we will get the data to our site using file_get_contents and decode the date using json_decode. Now lets see it in a function call and how it works.

PHP CODES:


//Get count of LinkedIn shares of URL
function get_LinkedIn($url) {

$json_string = file_get_contents('http://www.linkedin.com/countserv/count/share?url='.$url.'&format=json');
$json = json_decode($json_string, true);

return intval($json['count']);

}
//Get count of Stumble views of URL
function get_StumbledUpon($url) {

$json_string = file_get_contents('http://www.stumbleupon.com/services/1.01/badge.getinfo?url='.$url);
$json = json_decode($json_string, true);

return intval($json['result']['views']);

}

//Get count of Del views of URL

function get_Del($url) {

$json_string = file_get_contents('http://feeds.delicious.com/v2/json/urlinfo/data?url='.$url);
$json = json_decode($json_string, true);

return intval($json[0]['total_posts']);

}

After getting the results from the API site, its time to show it on our site, here’show it is.

HOW TO VIEW:


//stumble count
$get_StumbledUpon = get_StumbledUpon(URL);

echo $get_StumbledUpon;
//LinkedIn shares
$get_LinkedIn = get_LinkedIn(URL);

echo $get_LinkedIn;
//Delicous
$get_Del = get_Del(URL);

echo $get_Del;

 

Sparky! we get the Stumbles, LinkedIns, and Delicious shares of our URL using the PHP and we can now design it in the way we wanted. Help others to know this tutorial by sharing this to the social sites.

DEMO DOWNLOAD

Incoming search terms:

wilbert Santos

He is the founder and the man behind Upgraded Tutorials that focuses on creative and helpful web development tutorials. He is a Web Developer and knows CodeIgniter, WordPress and other frameworks. He loves web development and creating cool stuff. Add him on Facebook and Google

Worth Reading Topics