Twitter - I Only Recieve 20 Tweets From The User_timeline
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();
});
});
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.
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error