How many times a web link has been shared on Twitter

Twitter share button and Facebook share button are the most used buttons to share links on Internet. You can read Facebook count as I’ve explained here, and you can also read the number of the times that your urls have been tweeted on Twitter.

The code is very simple because there is a very simple public api to call. So, let’s call the twitter api, and parse the results. The results are parsed with the preg_match function but you can use also the json_decode¬†function, probably it is better. As you can see there is no need to use curl¬†library, we can just use file_get_contents.

If you store this count and the facebook total like count, you can show those data better on your site and you can use those data to make some “top stories” list.

function readTwitterShares($url) {
 $s = file_get_contents("".
   return isset($ar[2]) ? $ar[2] : 0;

echo readTwitterShares("");

This function will be soon included in the Mini Bots Class.

Anything to say?

Comments with Facebook or below with WordPress

Sorry, WordPress comments are closed on old posts.