This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.
Close popover

Table of Contents

Connecting to Twitter by using OAuth 2.0

You can connect to Twitter from the Pega® Platform to follow news trends or to collect comments about your organization or product. You can take advantage of positive comments and respond when a discussion of your product is negative.

Beginning with Pega 7.2, your Pega Platform application can act as an OAuth 2.0 client (consumer) to access private resources that are stored on external websites such as Twitter. OAuth is an open standard for authorization. Use OAuth to access private resources stored on one website and use them on another site without sharing your user name and password for the first site with the second site.

Pega Platform supports the client credentials grant type in OAuth 2.0. In this grant type, your application obtains client credentials to generate an access token, which gives you access to private resources in the external application for a defined period of time.

Refer to the following tasks to connect to Twitter and obtain a collection of tweets that match a specified query. For more information, see the Twitter Search API documentation.

Configuring the Twitter side

Create a Twitter account and register your Pega Platform application to obtain the details that are required to connect to Twitter from Pega Platform.

Creating a Twitter account

To create a Twitter account, go to https://twitter.com/signup and follow the instructions.

Registering your Pega Platform application

Register your Pega Platform application with Twitter.

  1. Go to https://apps.twitter.com/ and click Sign in.
  2. Follow the instructions for registering an application. Note that the Callback URL is where your application sends its response.
  3. Save the authentication, request token, authorization and access token URLs, and the consumer key and secret. You need this information to configure Pega Platform.​

Configuring the Pega side

Create an OAuth 2.0 provider and authentication profile by using the details that you obtained when you registered your Twitter application and by using the information from the Twitter Search API. Use the authentication profile in a REST connector, and then create a data page that you can run to view a collection of tweets.

Creating an OAuth 2.0 provider

Create an OAuth 2.0 provider and enter the details that you obtained when you registered your Twitter application.

  1. From the Records Explorer, expand the Security category.
  2. Right-click OAuth 2.0 Provider, and click Create.
  3. In the Name field, enter a name for the provider.
  4. In the Short description field, enter a short description.
  5. Click Create and open.
  6. In the Authorization code endpoint, Access token endpoint, and Revoke token endpoint fields, enter the information that you saved when you registered your Twitter application.
  7. Click Save. The client can now communicate with Twitter.

Creating an authentication profile

Create an authentication profile by using the OAuth 2.0 provider.

  1. From the Records Explorer, expand the Security category.
  2. Right-click Authentication Profile, and click Create.
  3. In the Type field, click OAuth 2.0.
  4. In the Name field, enter a name for the profile.
  5. In the Short description field, enter a description of the profile.
  6. Click Create and open.
  7. In the OAuth provider field, select Twitter.
  8. In the Grant type field, select Client credentials.
  9. In the Identifier and Secret fields, enter the information that you saved when you registered your Twitter application.
  10. Click Save.

Creating a REST connector

Create a REST connector by using the authentication profile and details that you obtained when you registered your Twitter application and by using the Twitter documentation for the Search API.

  1. From the Records Explorer, expand the Integration-Connectors category.
  2. Right-click Connect REST, and click Create.
  3. In the Label field, enter a label for the connector.
  4. In the Apply to field, select the class to which this connector applies.
  5. Click Create and open.
  6. On the Service tab, in the Resource path field, enter the resource URL of the Twitter Search API, for example, https://api.twitter.com/1.1/search/tweets.json.
  7. In the Authentication section, select Use authentication.
  8. Select the authentication profile that you created for Twitter.
  9. On the Methods tab, configure the request and response for the GET method by entering values for the query string parameters "q" and "lang" that are explained in the Twitter Search API documentation, as shown in the following example. The final result is a collection of tweets that match these parameter values.

    Configuring the request in a Connect REST rule form

    Configuring the response in a Connect REST rule form

  10. Click Save.

Creating and running a data page

Create a data page by using the REST connector as a data source and run the data page to see a collection of tweets.

  1. From the Records Explorer, expand the Data Model category.
  2. Right-click Data Page, and click Create.
  3. In the Label field, enter the purpose of the data page.
  4. In the Apply to field, select the class to which this data page applies.
  5. On the Definition tab, in the Data sources section, in the Name field, select the connector created as a data source.
  6. In the Method field, select Get, as shown in the following example.

    Completing the Definition tab of the Data Page rule form

  7. Click Save.
  8. Run the data page by clicking Actions > Run. The result is a collection of tweets that match the values that you provided for query string parameters "q" and "lang" in the REST connector. The tweets are mapped to pyDescription, as shown in the following example.

    Running a data page


60% found this useful


Related Content

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.