2

I am blink an led every time there is a new tweet. My script was working fine till yesterday. Today when i run my script its showing me duplicates tweets like this.

Twitter Streaming api shows duplicate tweets

I am using node.js ,twitter api and johnny-five

Here is my script

//INITIALIZING TWITTER API
var Twitter = require('twitter');

var client = new Twitter({
    consumer_key: 'asdf',
    consumer_secret: 'asdf',
    access_token_key: 'asdf',
    access_token_secret: 'asdf'
});

//INITIALIZING JOHNNY-FIVE API
 var five = require("johnny-five"),
    // or "./lib/johnny-five" when running from the source
    board = new five.Board();

board.on("ready", function() {
//INITIALIZE PINS 
    var red = new five.Led(2);
    var yellow = new five.Led(5);
    var green = new five.Led(8);
    red.on();
//TURN OFF LED  
    yellow.stop();yellow.off();
    green.stop();green.off();       

    client.stream('statuses/filter', {track: '#f8'}, function(stream) {
    stream.on('data', function(tweet) {
    console.log("\n"+tweet.text);
    red.stop();red.off();
    yellow.blink(100);
    board.wait(400,function(){
        yellow.stop();yellow.off();
        red.on();
    }); 
    });
    stream.on('error', function(error) {
    throw error;
    });
});
});

In this script there are three led declared red one indicates there are no tweets at the moment and yellow led blinks every time there is a new tweet and the green one is just sitting there doing nothing(I was planning to add more logic to my script with green led).

One more thing i noticed is that duplicates tweets are occurring with trending hashtags like #f8 and others. i used hashtags which are not trending and i was working fine.

Skyyy
  • 1,539
  • 2
  • 23
  • 60

0 Answers0