Search code examples
twitterpubnub

Filtered Pubnub Twitter stream not returning results


I'm consuming the PubNub Twitter stream and getting data on the console successfully. What I'm having trouble with, though, is the number of results. This is the code:

PUBNUB({
    subscribe_key: 'sub-c-78806dd4-42a6-11e4-aed8-02ee2ddab7fe'
}).subscribe({
    channel : 'pubnub-twitter',
    callback: processData
});

function processData(data) {
  if(data.text.toLowerCase().indexOf("#brexit")>-1)
    {
      console.log(data.text);
    }
}

I'm getting results on my console for this too, but they're really slow (I had to wait about seven minutes to get two tweets, while on the Twitter app, there are are at least 3-5 tweets with this hashtag every minute).

Is there a faster/more efficient way to filter the stream?


Solution

  • Are you using your own Twitter connection or the stream from this page?

    https://www.pubnub.com/developers/realtime-data-streams/twitter-stream/

    This stream represents only a small fraction of the entire Twitter firehose, so it is very possible that you'd only get a hashtag match every few minutes.

    If you want a specific hashtag you should create your own Twitter to PubNub stream. I wrote this blog on how to do it with just a little bit of code.

    https://www.pubnub.com/blog/2016-04-14-connect-twitter-and-pubnub-in-one-line-of-code-with-nodejs-streams/