Question

I'm using the following code to get the latest tweets from a specific hashtag

$(document).ready(function(){
getLatestTweets();
function getLatestTweets(){
    var url = "http://search.twitter.com/search.json?q=%23syria&result_type=recent&rpp=3&callback=?";

    $.getJSON(url, function(json){
        alert('reached');
        var html = '<ul>';
        $.each(json.results, function( key, result){
            html += '<li><a href="#">' + '> ' + result.text + ' ...' + '</a></li>'; 
        });
        html += '</ul>';
        $('#archive-twitter').append(html);
    });
}
});  

this code was working fine two days ago but it stopped working today. now the getJSON method won't succeed even though that when i use the following link

http://search.twitter.com/search.json?q=%23syria&result_type=recent&rpp=3

in the browser i get the actual json data

i don't know what is the problem?

UPDATE: i added a test link to clarify the problem http://latakiancoder.com/twitter-test.php

Was it helpful?

Solution

I've tried proxified server side the request and works:

JS code:

$(document).ready(function(){
                getLatestTweets();
                function getLatestTweets(){
                    var url = "http://search.twitter.com/search.json?q=%23syria&result_type=recent&rpp=3";

                    $.getJSON("proxy.php", { url: url }, function(json){
                        var html = '<ul>';
                        $.each(json.results, function( key, result){
                            html += '<li><a href="#">' + '> ' + result.text + ' ...' + '</a></li>'; 
                        });
                        html += '</ul>';
                        $('#archive-twitter').append(html);
                    });
                }
            });  

proxy.php code:

<?php
    $url = $_GET['url'];
    $json = file_get_contents($url);
    echo $json;
?>

OTHER TIPS

Your URL is working fine at my end.

Make sure include_entities is set to true to get hashtag results.

http://search.twitter.com/search.json?q=ipl&result_type=recent&include_entities=true

After looking into the above url response Header:

X-Frame-Options SAMEORIGIN
X-XSS-Protection    1; mode=block

Seems like twitter has retired API v1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top