Twitter Adapter Samples

About The Sample

This sample demonstrates the TIBCO StreamBase® Twitter adapters to enable listening to Twitter status messages, commonly called tweets.

Setup

To run this sample, you must edit the provided sbd.sbconf file to supply values for the following:

  1. consumerKey

  2. consumerSecret

  3. accessToken

  4. accessTokenSecret

You must also configure the sample with appropriate OAuth tokens. See Twitter Input Adapter for instructions.

Running The Samples in StreamBase Studio

  1. In the Package Explorer, double-click to open the twitter.sbapp. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Manual Input view, switch the stream to ControlInput, enter user into the Command field and then click Send Data to send the control tuple.

  4. In the Application Output view, observe the InputStatus tuple which gives details about the connection to the User stream which this sample starts by default on application start up.

  5. In the Manual Input view, switch the stream to ControlOutput, enter tweet into the Command field and then a short status into the Tweet\Status field and then click Send Data to send the control tuple.

  6. In the Application Output view, observe tuples emitted on the OutputStatus and Tweets output streams.

  7. Select the tuple emitted from the Tweets stream, then use the triangles next to the data fields displayed to analyze and understand their structure.

  8. Experiment with other commands on the ControlOutput and ControlInput streams as shown by notes included in the sbapp.

  9. Press F9 or click the Stop Running Application button.

Running This Sample in Terminal Windows

This section describes how to run this sample in UNIX terminal windows or Windows command prompt windows, follow the steps in this section.

On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open six terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.

  2. In window 1, type:

    sbd twitter.sbapp
  3. In window 2, type:

    sbc dequeue Tweets

    This window will display tuples dequeued from the adapter's tweets port.

  4. In window 3, type:

    sbc dequeue InputStatus

    This window will display tuples dequeued from the adapter's primary output port.

  5. In window 4, type:

    sbc dequeue OutputStatus

    This window will display tuples dequeued from the adapter's primary output port.

  6. In window 5, type:

    sbc enqueue ControlInput
  7. In window 5, type:

    user, null, null, null, null, null, null

    and press Enter.

  8. Observe in window 3 that a single tuple is emitted from the InputStatus stream. This tuple contains various fields that detail the status of the connection.

  9. In window 6, type:

    sbc enqueue ControlOutput
  10. In window 6, type:

    tweet,"testing a tweet,null,null,null,null,null,null",null

    and press Enter.

  11. Observe in window 2 that a single tuple is emitted from the Tweets stream. This tuple contains various fields that detail the tweet received.

  12. In window 2, type Ctrl+C, then the following command to terminate the server and dequeuer:

    sbadmin shutdown

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, select FileLoad StreamBase Sample.

  • Select Twitter adapter from the StreamBase Standard Adapters category.

  • Click OK.

StreamBase Studio creates a single project containing the sample files.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_twitter

See Default Installation Directories for the default location of studio-workspace on your system.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/adapter/embedded/twitter

See Default Installation Directories for the default location of studio-workspace on your system.