Search code examples
node.jstwitter

Twitter steam API randomly stopped working


I am using node.js and twit to track tweets which include the hashtag #DisasterMgtUWI in real time. It was working at first, and I managed to get the first two that I made from a test account. On the 3rd tweet, I included an image in the tweet. However, from this point onwards, no tweets that I made were logged to the console, even after restarting my server. My code is shown below:

const Twit = require('twit')
require('dotenv/config')
const T = new Twit({
    consumer_key: process.env.TWITTER_API_KEY,
    consumer_secret: process.env.TWITTER_API_SECRET,
    access_token: process.env.TWITTER_ACCESS_TOKEN,
    access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})

const stream = T.stream('statuses/filter', {track: '#DisasterMgtUWI'})

stream.on('tweet', tweet => {
    console.log(tweet)

})

Does anyone know why my code randomly stopped working? I'm at a loss.


Solution

  • I fixed the problem by hard-coding the API key values rather than using the variables from a .env file.