Using Java Invoke that Makes a REST call to Search Twitter
In this sample, Java Invoke makes a REST call to Twitter to search for a specified term. The application module contains the user-written code, user jars, and processes. There is no dependency on a Shared Module.
Prerequisites
- Create new app on - https://apps.twitter.com/ and generate Access Token, Access Token Secret, Consumer Key, Consumer Secret for the app created and use it in the parameters for SearchTwitter Activity.
- To create a token:
- Login to https://apps.twitter.com/ with your Twitter account.
- Click Create New App.
- Provide Name and Description and create your Twitter application. Your application is successfully created.
- Go to API Keys Tab and click Create my access token. Your application access token is successfully generated.
- Click Test OAuth. You should see the OAuth Settings page which has the following tokens generated - Consumer key, Consumer secret, Access token, Access token secret.
Procedure
Result
A Search_Output.log is generated in C:\tmp\RESTInvokeToTwitter folder as per the value specified in the Module Property.
This file contains a collection of relevant Tweets matching a specified query. In this case, it is "Lady Gaga".
Understanding the Configuration
The project contains the following process:
RESTInvokeToTwitter Process: This process has two Java Invoke activities: OpenTwitterConnection and SearchTwitter. The source code for these activities is located under src directory under com.example.TwitterConnection package in the same project. OpenTwitterConnection activity creates a TwitterConnection object which is then passed to SearchTwitter activity.
AccessToken, AccessTokenSecret, ConsumerKey, and ConsumerSecret are required for authentication to the Twitter Account. The steps to generate these is mentioned in the Prerequisite section.
The Java invoke uses Twitter API v1.1 which requires this request to be authenticated using OAuth.
If you receive an error message such as:
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
Then, ensure that you have generated Access Token, Access Token Secret, Consumer Key, and Consumer Secret as per the steps specified in Prerequisites section.