Example JSON HTTP request for twitter api?

后端 未结 2 1981
臣服心动
臣服心动 2021-02-06 12:06

I want to make a request to the twitter api. This is the example provided in the documentation (https://dev.twitter.com/docs/api/1/get/search):

GET:

http://sear         


        
2条回答
  •  忘了有多久
    2021-02-06 12:37

    Look if this helps, I made an example for you:

    Basically the HTML code contains 2 inputs. one for the button and one for the query string.

    
    
        example
    
    
       
    Tweets will go here.

    After pressing the search button, you'll send a request to twitter asking for 5 results (rpp) containing the query string.

    Here's the javascript for this page:

    function searchTwitter(query) {
        $.ajax({
            url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
            dataType: 'jsonp',
            success: function(data) {
                var tweets = $('#tweets');
                tweets.html('');
                for (res in data['results']) {
                    tweets.append('
    ' + data['results'][res]['from_user'] + ' wrote:

    ' + data['results'][res]['text'] + '


    '); } } }); } $(document).ready(function() { $('#submit').click(function() { var params = { q: $('#query').val(), rpp: 5 }; // alert(jQuery.param(params)); searchTwitter(params); }); });

    The trick is the jQuery.param() function that you'll pass the params for the search/request

    See it running here:

    http://jsfiddle.net/73L4c/6/

提交回复
热议问题