twitter search api with jquery error

后端 未结 2 2014
臣服心动
臣服心动 2020-12-28 19:52

I need to request a twitter search with jquery using twitter api. After read documentation I write this code:

  $.getJSON(\"http://search.twitter.com/search.         


        
相关标签:
2条回答
  • You need to write it a bit differently, like this:

    $.getJSON("http://search.twitter.com/search.json?callback=?&q=stackoverflow", 
      function (r) {
        console.log(r);
    });
    

    To trigger JSONP it's looking for explicitly callback=?, which isn't in your named function version. To use the named callback, you're better off going with the $.ajax() full version:

    $.ajax({
      url: "http://search.twitter.com/search.json?q=stackoverflow",
      dataType: "jsonp",
      jsonpCallback: "myFunction"
    });
    
    function myFunction(r) { console.log(r); }
    
    0 讨论(0)
  • 2020-12-28 20:25

    Just to add a bit more to the answer you can use the following code to display text within each returned tweet.

    $.getJSON("http://search.twitter.com/search.json?callback=?&q=stackoverflow",
    
    function(data){
    
    for (i=0; i<data.results.length; i++){
    
    $("#tweets").append("<p><strong>Text: </strong>" + data.results[i].text + "<BR/>" + "<p><strong>Created at: </strong>" + data.results[i].created_at +"</p><br /><br />");
    
    }
    });
    

    Then within your body html put the following div

    <div id="tweets"></div>
    
    0 讨论(0)
提交回复
热议问题