Getting urls from tweets, converting short url to original and getting numbers of tweets containing that url


Here I am getting url from tweets, converting that url to long url.

And then getting count value for numbers of tweets containing that url.

$reg_exUrl = "/(?<![\>https?:\/\/|href=\"'])(?<http>(https?:[\/][\/]|www\.)([a-z]|[A-Z]|[0-9]|[\/.]|[~])*)/";
// The Text you want to filter for urls
$text = "Make this Xmas super powerful with #Krrish3 on !\ ";
// Check if there is a url in the text

    if(preg_match($reg_exUrl, $text, $url)) {
        preg_match_all($reg_exUrl, $text, $urls);
        foreach ($urls[0] as $url) {
        echo "{$url}<br>";
        $full = MyURLDecode($url);
        echo "full is: $full<br>";
        $feedUrl = "$full";
        $json = file_get_contents($feedUrl);
        $code = json_decode($json,true);
        echo "1";
        echo "Numbers of tweets containing this link : ", $code['count'];
        echo "2";
    } else {
    echo $text;


1. Decoding some twitter tiny urls again give biturl(i.e. again tiny url)
2. Getting number of tweets(count value) containig that url. Above code give it, but for most of url it show 0 though they have count value

Any suggestion for improvement?


Hi @karimkhan_it,

Challenge #2 (zero count) is because you are using a retired api. Version 1 of the REST API has been retired ( and version 1.1 requires OAuth authentication. Additionally there is no direct method for getting the count of a URL from a tweet unless it’s via the official tweet button or you create an app to connect to the streaming API and do your own filtering. Ref this discussion:

Adam Green has a lot of info about working with the streaming APIs: