Search code examples
ajaxnode.jsapitwitteribm-cloud

How to get more than 20 tweets with Bluemix Twitter Insights?


I'm using this code to create a Twitter Insight app in Bluemix. However, I can't find any documentation on how to increase the number of tweets retrieved by the API. I tried using size and count as parameter in the query but without result. Is it possible to get more tweets?

    $.ajax({
        url:'/api/search/',
        type: 'GET',
        contentType:'application/json',
        data: {
            q: term,
            size: 100
        },
        success: function(data) {
            // do stuff
        },
        error: function(xhr, textStatus, thrownError) {
            // do error stuff
        }
    });

Solution

  • The server side code you are using has a hard coded value of 20 for the number of tweets returned in the app.js file:

    var MAX_TWEETS = 20;
    
    // callback - done(err, data)
    function insightRequest(path, query, done) {
        request({
            method: "GET",
            url: insight_host + '/api/v1/messages' + path,
            qs: {
                q: query,
                size: MAX_TWEETS
            }
        }, function(err, response, data) {
    

    You have to modify that value for the max number you want to return, or make a parameter you can pass to function.