TweetMeme is an excellent site that offers various types of Twitter-based social integration to your website. They’re particularly relevant when it comes to finding current news of interest because they measure the number of times a certain website has had their story published or tweeted to Twitter. Those stories that have the most tweets are featured on the front page of the their website.
I like to know how many times certain pages from certain websites are published to Twitter, and TweetMeme’s API makes it easy to find that information. It’s also nice to be able to extract that information and publish the number of tweets on my own page in a format that best fits my own website.
The TweetMeme API will return an XML document that you can style in any way you wish. You can include the number of tweets on your page in any format and, if you so choose, link back to your stories page on the tweetmeme.com website.
This PHP function will output only one element as text – the tweet count.
<?php
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;
}
}
?>
I use this API integrated with another application to aggregate the popularity of posts over 40 of my websites. It sends me a nice summary every night and posts the data to a database so I can measure the success or failure of particular types of information.
The XML output will look like this:

The Tweetmeme URL count is highlighted
The output of the PHP function will output a plain text number.
Usage
Usage is easy.
<?php
echo tweetCount("http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30");
?>
If you have any questions regarding what I’ve described above, please email or leave a comment. I’ll be happy to help
I’ll publish some WordPress shortcode shortly that enables dynamic count data to be parsed in posts as text.
You can download the above code below.
|
|
Download: Tweetmeme URL Count |
If you liked this article, you may also like:


I’ve been trying to get this to work on my homepage which shows multiple posts.
It throws up errors saying your can’t re use the same function… any thoughts?
Keep in mind that the above code is really only useful for development purposes. If you’re interested in a tweet button, perhaps you might just want to use one of TweetMeme’s retweet buttons.
If you wanted use of the function for other purposes, send me a message via the form at the top of this page with the error message you’re receiving and I’ll do what I can to help. Provide as much information as possible. Alternatively, my email is marty @ [this domain name].