PHP - Tweet url counter

php-tweet-url-counter

With the twitter api you can retrieve tweet count for a specific url. You can use full address including http or just a domain name for the url parameter value.

function get_tweet_count($url){
        $data = file_get_contents("https://cdn.api.twitter.com/1/urls/count.json?url=" . $url);
        $data = json_decode($data, true);
        return $data;
}

$tweets = get_tweet_count("http://php.net/");
print_r($tweets);
echo "Tweets count: " . $tweets['count'];

Output:

Array
(
    [count] => 6676
    [url] => http://php.net/
)

Tweets count: 6676
- Posted by rutix to Php
comments powered by Disqus