Reputation: 23
PROBLEM
So im trying to create a twitter bot and everything was going fine until i tried to auto reply to users who follow me. I'am learning and was watching from this tutorial Coding Train Twitter Bot(LINK) but i seem to get this error(PHOTO) even tho i did everything exactly the same.
Im Using:
Importing Packages
var Twit = require('twit');
var Keys = require('./private_auth_keys');
var T = new Twit(Keys);
Stream Setup.
I belive the bug is somewhere in the stream part but i dont get it... i did everything the same as the video. Maybe twitter blocked this from their API? idk what im talking about, but any feedback would be awesome.
var stream = T.stream('user');
stream.on('follow', followed);
function followed(eventMsg) {
console.log("New Follower Reply Sent!");
var Name = eventMsg.source.name;
var screenName = eventMsg.source.screen_name;
tweetIt('Heyyy .@' + screenName + ' thanks for the follow! Do you like memes? #RateThatMeme');
}
Reply/Tweet Function
function tweetIt(txt) {
var tweet = {
status: txt
}
T.post('statuses/update', tweet, tweeted);
function tweeted(err, data, response) {
if (err) {
console.log("oof! Something went wrong!");
} else {
console.log("Tweet sent successfully!");
}
}
}
Error Message
events.js:167 throw er; // Unhandled 'error' event ^
Error: Bad Twitter streaming request: 401 at Object.exports.makeTwitError (C:\Users\admin\Desktop\Projects Code Train\node\node2\node_modules\twit\lib\helpers.js:74:13)....etc
Upvotes: 1
Views: 1008
Reputation:
Twitter user streams were retired in August so this code will no longer work as is.
Upvotes: 1
Reputation: 901
401 status code means you are not unauthenticated - there should be additional WWW-Authenticate
header in response that will tell you more.
I think twitter API changed since this tutorial was recorded and you have to do a bit more now to be able to access it, this is probably a reason for 401 status. as far as I can see, the author moved to mastodon with this tutorial lately because of that.
Upvotes: 1