View Single Post
Old 04-16-2011, 10:51 PM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
Quote:
Originally Posted by Brujah View Post
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;
      }
  }

?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote