Reputation: 583
Am trying to get tweets from my twitter account using the Twitter API but all combinations keep on failing. With all node_modules present and everything seeming fine I get an error. Here is the full code:
var client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
//Retrieving tweets
client.get('statuses/show/:id_str', {'id_str':'749000808381968384'}, function (error, tweet, response) {
if (error){
console.log(error);
} else {
console.log(tweet);
// console.log(response); // Raw response object.}
}});
Here is the error:
[ { message: 'Sorry, that page does not exist', code: 34 } ]
Kindly help by correcting the problem in the code, I have tried my best to look for answers from other sources in vain
Upvotes: 0
Views: 118
Reputation: 353
The endpoint that you are using statuses/show/:id_str is to fetch the status specified by id_str and not the statuses of the user.
You should use the endpoint statuses/user_timeline to get the tweets of the authenticated users.
You could try the code suggested by Eric.
Upvotes: 0
Reputation: 583
Fortunately I found the answer from twitter npm. This is the code to use:
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
var params = {screen_name: 'nodejs'};
client.get('statuses/user_timeline', params, function(error, tweets, response) {
if (!error) {
console.log(tweets);
}
});
Screen name is your username. The one that begins with @ on your twitter profile.
Upvotes: 1