Quote:
Originally Posted by Brujah
How do you get the social metrics without a plugin? Facebook Likes, Twitter Mentions, etc...
|
here is something to get you started.
Code:
<?php
// retweets for url
function tweetCount($url)
{
$content = file_get_contents("http://api.tweetmeme.com/url_info?url=" . $url);
$element = new SimpleXmlElement($content);
$retweets = $element->story->url_count;
if ($retweets) {
return $retweets;
} else {
return 0;
}
}
// facebook likes for url
function likeCount($url)
{
$data = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=json"));
if ($data) {
return $data[0]->like_count;
} else {
return 0;
}
}
// declicious posts for url
function deliciousCount($url)
{
$data = json_decode(file_get_contents("http://feeds.delicious.com/v2/json/urlinfo/data?url=$url"));
if ($data) {
return $data[0]->total_posts;
} else {
return 0;
}
}
// digg count for url
function diggCount($url)
{
$data = json_decode(file_get_contents("http://services.digg.com/1.0/endpoint?method=story.getAll&link=$url&type=json"));
if ($data) {
return $data->stories[0]->diggs;
} else {
return 0;
}
}
// reddit score for url
function redditCount($url)
{
$data = json_decode(file_get_contents("http://www.reddit.com/api/info.json?url=$url"));
if ($data) {
return $data->data->children[0]->data->score;
} else {
return 0;
}
}
// stumbles for url
function stumbleCount($url)
{
$data = json_decode(file_get_contents("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url"));
if ($data) {
return $data->result->views;
} else {
return 0;
}
}
// bit.ly clicks for url
function bitlyCount($url,$login,$apikey)
{
$data = json_decode(file_get_contents("http://api.bit.ly/stats?version=3&shortUrl=$url&login=$login&apiKey=$apikey&format=json", true));
if ($data) {
return $data->results->clicks;
} else {
return 0;
}
}
?>