GitHub - pusher-community/pusher-datasource-api: An API for streaming data in real time through Pusher channels. (original) (raw)

Pusher Data Stream

A service that lets users search the Twitter stream for search terms using Pusher.

How it Works

Client Usage

Using the Pusher JS library, the client should subscribe to a channel name, where the channel name is the search term. Because of restrictions on Pusher channel names, this name should be Base64 encoded:

// Client var pusher = new Pusher(YOUR_APP_KEY); var channelName = 'javascript'; var channel = pusher.subscribe(btoa(channelName));

channel.bind('new_tweet', function(data) { console.log('got tweet', data.tweet); console.log('matched search term', data.searchTerm); });

Configuring the server

You'll need to configure your Pusher app to send channel existence webhooks to this server, which accepts POST /webhook. The server will then start the Twitter stream and trigger events when new tweets are found.

The server supports searching for multiple keywords at once and will stop searching once all users vacate a given channel.

To run the server you'll need to make sure you've set the following environment variables. If you place them in a .env file, they will be loaded automatically by Dotenv.

TWITTER_CONSUMER_KEY="..."
TWITTER_CONSUMER_SECRET="..."
TWITTER_ACCESS_TOKEN="..."
TWITTER_ACCESS_SECRET="..."

PUSHER_APP_ID="..."
PUSHER_APP_KEY="..."
PUSHER_APP_SECRET="..."