Reputation: 49
Please i need help on how to fetch data from twitter api for a week. i'm using nodeJs to write the code and it doesn't seem to work well.
I'm using the twit module in nodeJs btw.
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1; //January is 0!
var year = today.getFullYear();
let months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
for (let i = 0; i < 7; i++) {
if (day > 0) {
day--;
}
if (day == 0) {
month = month - 1;
day = months[month - 1];
}
console.log(day, month, year);
}
let params = {
q: `to:${firstBrand} since:${year}-${month}-${day-1} until:${year}-${month}-${currentDay}`,
count: 5000,
language: 'en',
entities: false
};
let param = {
q: `to:${secondBrand} since:${year}-${month}-${day-1} until:${year}-${month}-${currentDay}`,
count: 5000,
language: 'en',
entities: false
};
t.get('search/tweets', params, dataGotten);
Upvotes: 0
Views: 631
Reputation: 3154
Assuming all your setup is done correctly:
const Twit = require('twit')
const T = new Twit({
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...',
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
});
I would try this:
t.get('search/tweets', params, function(err, data) {
console.log(data);
});
By the way, params
is optional argument, so first of all try how it works without them:
t.get('search/tweets', function(err, data) {
console.log(data);
});
Upvotes: 1