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…

Ottobre 19, 2012

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("http://urls.api.twitter.com/1/urls/count.json".
   "?callback=?&url=".urlencode($url));
   preg_match("#(\"count\"):([0-9]*)#",$s,$ar);
   return isset($ar[2]) ? $ar[2] : 0;
}

echo readTwitterShares("http://www.dailybest.it");

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

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “How many times a web link has been shared on Twitter”

Recommended

How to read facebook likes count from PHP

When you add facebook like button to your site, probably, you also want to save the number of likes of…

Ottobre 8, 2012

get MySpace events with a PHP function

Here is a function to read the concerts for a myspace band page. This code retrieves the “shows page” for…

Febbraio 21, 2011

New version of Mini Bots PHP Class (v.1.4)

I’ve added three more bots to the Mini Bots Php Class, now the version number is 1.4 and it has…

Gennaio 20, 2010

PHP to get twitter infos and avatar

I’ve just updated the Mini Bot Php Class with an improved version of the twitterInfo function, here is the code…

Marzo 1, 2010

PHP Web page to text function

I’ve found this nice small bot on the www.php.net site, thanks to the author of the script on the preg_replace…

Gennaio 16, 2010

Bot that retrieves url meta data and other infos

From a given url this function retrieves page title, meta description, keywords, favicon, and an array of 5 images to…

Gennaio 12, 2010