Ad

Twitter - I Only Recieve 20 Tweets From The User_timeline

- 1 answer

var options = {
method: 'GET',
url: 'https://api.twitter.com/1.1/statuses/user_timeline.json?',
qs: { "screen_name": "Screen_name"} ,
json: true,
headers: {
  "Authorization": "Bearer " + token.access_token
  }
};


request(options, function(error, response, body){
   console.log("length",body.length)
});

i am trying to get all tweets but for some reason i only get 20, eventought the api call can get up to 3200 tweets.

So i am wondering how can i get all the tweets of this account (currently 700+) i saw a count being listed but for some reason i cant find a way to start a segment.

Hopefully someone can help me.

EDIT:

after the answer of pii_kee , i came to the conclusion that this is what needs to be done to get all tweets :

    var firstOptions = {
    method: 'GET',
    url: 'https://api.twitter.com/1.1/statuses/user_timeline.json',
    qs: {"screen_name": "Company", "count": 200},
    json: true,
    headers: {
      "Authorization": "Bearer " + token.access_token
    }
  };
    var array = [];
    var go = true;
    async.whilst(function () {
      return go;
    },function(next){
      request(firstOptions, function (error, response, body) {
        firstOptions.qs.max_id = body[body.length - 1].id;
          array = array.concat(body);
          if(body.length !== 200) {
            go = false;
          }
        next();
      });
    });
Ad

Answer

Try adding count: 200 in the qs object to get about 200 tweets per request. To get older tweets you have to set the max_id parameter properly, otherwise it will return most recent tweets only. Take a look at the reference of statuses/user_timeline API endpoint for detailed meaning of these parameters.

Also, try reading this guide on working with timelines using this method.

Ad
source: stackoverflow.com
Ad