Chapter 26. Connecting to Twitter

To connect to Twitter in an integration, the main steps are:

You need a Twitter developer account to authorize access from your Fuse Online environment to Twitter. If you do not already have a Twitter developer account, go to https://apps.twitter.com, sign in to Twitter, and click Apply for a developer account. Obtaining the developer account is quick when you provide a professional email address, such as me@redhat.com rather than a personal address such as you@gmail.com.

26.1. Registering Fuse Online as a Twitter client application

In an integration, to connect to Twitter, the first thing you must do is register your Fuse Online environment as a client application that can access Twitter. This lets you create any number of integrations that connect to Twitter. In other words, you need to register a particular Fuse Online environment with Twitter only once.

In each Fuse Online environment, there can be only one registration of Fuse Online as a Twitter client application. However, while each Twitter connection uses the same registration, it can use different user credentials.

Prerequisite

You are logged in to Fuse Online.

Procedure

  1. In Fuse Online:

    1. In the left panel, click Settings.
    2. On the Settings page, near the top, to the right of the callback URL, click Copy Callback URL to copy the callback URL for your installation of Fuse Online to the clipboard. You will need this URL later in this procedure.
    3. Click the Twitter entry to display the Consumer API Key and Consumer API Secret Key fields.
  2. In another browser tab, go to your Twitter developer account, sign in if you need to, and then do the following:

    1. Click Projects & Apps.
    2. On the Overview page, scroll down to click Create an app.
    3. In the App name field, enter a name such as My Fuse Online Client.
    4. In the Application description field, enter a tip such as For leveraging tweets.
    5. Scroll down to Set up Your App and then click App settings.
    6. Next to Authentication Settings, click Edit.
    7. Switch on the Enable 3-legged OAuth option.
    8. In the Callback URLs field, paste the URL that you copied at the beginning of this procedure. It should be something like this: https://app-proj912876.7b63.fuse-ignite.openshiftapps.com/api/v1/credentials/callback
    9. In the Website URL field, paste the URL again and remove api/v1/credentials/callback from the end of the URL.

      You can skip the next few fields.

    10. Click Save.
    11. At the top of the page for the app that you just created, click the Keys and tokens tab.
    12. Under Consumer Keys, click View keys.
    13. Copy the API key.
  3. Return to your Fuse Online Settings page and paste the Twitter consumer API key into the Fuse Online Twitter Consumer API Key field.
  4. Return to the Twitter Keys and tokens tab and copy the consumer API secret key.
  5. Return to your Fuse Online Settings page and paste the Twitter consumer API secret key into the Fuse Online Twitter Consumer API Secret Key field.
  6. Click Save.
  7. Click the Twitter entry to collapse it.

26.2. Creating a Twitter connection

To create an integration that obtains data from Twitter, you must first create a Twitter connection. After you create a Twitter connection, you can use it in any number of integrations.

Prerequisites

  • You are logged in to Fuse Online.
  • Fuse Online is open in a web browser.
  • You registered your Fuse Online environment as an application that can access Twitter.
  • You added the Twitter consumer API key and consumer API secret key that you received after registration to the Fuse Online Settings page.

Procedure

  1. In Fuse Online, in the left panel, click Connections to display any available connections.
  2. Click Create Connection to display the available connectors. A connector is a template that you use to create one or more connections.
  3. Click the Twitter connector.
  4. Click Connect Twitter to display a Twitter authorization page. You might need to log in to Twitter before you see the authorization page.

    If Connect Twitter does not appear, then your Fuse Online environment is not registered as a Twitter client application. See Registering Fuse Online as a Twitter client application. When you try to create a Twitter connection and your Fuse Online environment is not registered as a Twitter client application, then Fuse Online displays multiple fields that prompt for authorization information. While you can create a Twitter connection by entering values in these fields, it is not recommended.

  5. Click Authorize app to return to Fuse Online.
  6. In the Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter Twitter Connect 1.
  7. In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter Sample Twitter connection that uses my Twitter login credentials.
  8. Click Save to see that the connection you created is now available. If you entered the example name, you would see that Twitter Connect 1 appears as a connection that you can choose to add to an integration.

26.3. Adding a Twitter connection to trigger integration execution

In a simple integration, the start connection can be a Twitter connection that triggers execution of the integration when it finds certain tweets or direct messages.

Prerequisites

  • You created a Twitter connection.
  • You are creating or editing a simple integration and Fuse Online is prompting you to choose the start connection.

Procedure

  1. Click the Twitter connection that starts the integration. When the integration uses the selected connection to connect to Twitter, Fuse Online uses the credentials defined in that connection.
  2. Select the action that you want the connection to perform. A Twitter connection that you add to an integration performs only the action that you choose:

    • Mention monitors Twitter for tweets that contain the Twitter handle for the Twitter account that the connection is authorized to access. Upon finding such a tweet, the connection returns it to Fuse Online, which triggers execution of the integration.
    • Retrieve periodically polls Twitter for direct messages sent to the Twitter account that the Twitter connection is authorized to access. Upon finding such messages, the connection returns them to Fuse Online, which triggers execution of the integration.
    • Search periodically polls Twitter for tweets that match criteria that you specify. Upon finding such tweets, the connection returns them to Fuse Online, which triggers execution of the integration.
  3. Configure the action that you selected:

    • Mention does not require any configuration.
    • Retrieve

      • Count has a default of 100 and you should not need to change this value, which affects internal behavior. However, do not set this value to less than 50 because doing so might decrease performance.

        The Retrieve action always returns all previously unreturned direct messages received in the last 30 days. If you do not select Ignore direct messages previously found, then the Retrieve action returns all messages that have been received in the last 30 days.

      • Delay is the period of time between polls. Twitter enforces rate limits, so you should not poll too often. The default interval is 5 seconds.
      • Ignore direct messages previously found returns only new messages when selected.
    • Search

      • Delay is the period of time between polls. Twitter enforces rate limits, so you should not poll too often. The default interval is 5 seconds.
      • Ignore tweets previously found returns only new tweets when selected.
      • Query is a Twitter-formatted search expression that specifies the tweets that you want the connection to return. The following table provides examples of what you can enter. More details are in this Twitter document for search operators.

        Query

        Results

        My Product

        Obtains tweets that contain both My and Product, but not necessarily My Product.

        "My Product”

        Obtains tweets that contain an instance of My Product.

        My OR Product

        Obtains tweets that contain an instance of My or Product or an instance of each one.

        My -Product

        Obtains tweets that contain an instance of My and do not contain an instance of Product.

        #MyProduct

        Obtains tweets that contain the MyProduct hashtag.

  4. Click Next to add the connection to the integration.

Result

The integration now has a start connection and Fuse Online is prompting you to choose the finish connection.

26.4. Adding a Twitter connection that sends a direct message

In the middle of a flow, or to finish a simple integration, you can add a Twitter connection that sends a direct message to a Twitter user. A direct message is a private message that goes to only the specified user.

Prerequisites

  • You created a Twitter connection.
  • You are creating or editing a flow and Fuse Online is prompting you to add to the integration. Or, for a simple integration, Fuse Online is prompting you to choose a finish connection.

Procedure

  1. On the Add to Integration page, click the plus sign where you want to add a Twitter connection.
  2. Click the Twitter connection that you want to add to the integration. When the integration uses the selected connection to connect to Twitter, Fuse Online uses the credentials defined in that connection.
  3. Select the Send action.
  4. In the Default Message field, enter the message that you want the connection to send when a data mapper step does not map the direct message content from a previous step to this Twitter connection. While you must enter a message when you configure this Twitter connection, a message that you map from a previous step has precedence over the message that you specify here.
  5. In the User field, enter the Twitter handle of the user who you want to send a direct message to. For example, both Aslan and @Aslan are correct.
  6. Click Next to add the connection to the integration.

Result

The connection appears in the middle or at the end of an integration visualization.