Skip to main content

Integration with Twitter using Mule ESB

article banner

Overview

In this blog post, we are going to explain a step by step procedure to integrate with Twitter using Mule ESB Twitter connector.

Versions

In this blog post, we would be using

  • Twitter Connector 3.2.0
  • Anypoint Studio
  • Mule ESB Server 3.5.2

Assumptions

  • To use this application in your project, a Twitter account needs to be created for testing. We can create an account by the URL https://twitter.com/signup and register using an email address.
  • A new Twitter app has to be created under Twitter developer apps in order to communicate with the Twitter account from Mule ESB application.  We can also connect to an existing app if it is already created. In this blog post, we will create a new Twitter app.

Configuring Twitter App

  • Go to https://apps.twitter.com/
  • Sign in and click on Create New App button
  • Fill the form and choose- Create the Twitter application button. A sample form is given below
Integration with Twitter using Mule ESB
  • Click on Keys and Access Tokens tab
  • Click on Create my Access Tokens
  • Make a note of Consumer Key, Consumer Secret, Access Token and Access Token Secret.
  • These keys will be used in Mule application to connect to Twitter
  • A sample screen is given below
Integration with Twitter using Mule ESB

Configuring MuleESB Twitter Connector

  • Create a new Mule Application
  • Click on Global Elements tab in the main flow
  • Click on Create Button
  • Select Twitter under Connector Configuration group
  • Add Consumer Key, Consumer Secret, Access Token and Access Token Secret in the corresponding text boxes
  • In the given example, the keys are read from a property file and the property file is loaded using PropertyPlaceholder global component
  • We can click on Test Connection button to verify connection to twitter before developing the main flow
  • A sample screen and XML configuration is given below
Integration with Twitter using Mule ESB, Configuring MuleESB Twitter Connector
<context:property-placeholder
location="file:${mule_home}/conf/twitter-config.properties" />
<twitter:config name="TwitterConfig" accessKey="${APIKey}"
accessSecret="${APISecret}" consumerKey="${consumerKey}"
consumerSecret="${consumerSecret}" doc:name="Twitter" />


Mule Flow to connect to Twitter and retrieve user details

  • Configure a flow as given below
Integration with Twitter using Mule ESB
<flow name="TwitterShowUserFlow" doc:name="TwitterShowUserFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="3333" path="twitterconnect" doc:name="HTTP" />
<twitter:show-user config-ref="TwitterConfig"
doc:name="ShowUser" />
<json:object-to-json-transformer
doc:name="Object to JSON" />
</flow>

Testing and Observation

  • Deploy the mule application
  • Hit the following URL on the browser

http://localhost:3333/twitterconnect

  • If the authentication details are correct, it shows a JSON message back on the browser with logged in user account details.

If you would like to find out more about how Systems Integration could help you make the most out of your current infrastructure while enabling you to open your digital horizons, do give us a call at +44 (0)203 475 7980 or email us at Salesforce@coforge.com

Other useful links:

Integration with LinkedIn using Mule ESB

Integration of Mule ESB with Microsoft Azure

Integration with Dropbox using Mule ESB

Related reads.

WHAT WE DO.

Explore our wide gamut of digital transformation capabilities and our work across industries.

Explore