1
votes

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

2
You should upgrade to API v1.1 which now require authentificated user. Seems like API v1 search has stop working using ajax request: dev.twitter.com/blog/planning-for-api-v1-retirement But i cannot find any official announcement concerning this. - A. Wolff
why the browser requests are working then!!, and can you provide any links or resources about authentication with jquery, i searched their documentation and didn't seem to find any thing about Javascript authentication. thanks. - hfatahi

2 Answers

1
votes

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;
?>
0
votes

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.