Overview
Facebook is a social networking website launched in February 2004. A user must register before they can use Facebook. After registering users can create a user profile, add other users as friends, exchange messages, post status updates and photos, share videos and receive notifications when others update their profiles. In this blog post, a step by step process of integrating with Facebook using Mule ESB Facebook connector is shown.
Versions and Assumptions
- In this blog post, we are using
- Facebook Connector 2.3.4
- Anypoint Studio
- Mule ESB Server 3.5.2
- To use this application in the project, we will need a Facebook account for testing
- We need to create a new Facebook app under Facebook developer apps to be able to communicate with the Facebook account from Mule ESB application
- We will be using OAuth2 authentication to connect to Facebook using Mule ESB Facebook Connector
Configuring Facebook App
- Go to https://developers.facebook.com/
- Click on My Apps
- Click on Create a New App button
- Add a unique display name, namespace and select a category
- Click on Create App Id
- Click on Show button and make a note of the App ID and App Secret. The App ID and App Secret will be used later in Mule Facebook Connector configuration
A sample screen shot for the Facebook app is given below.
Facebook App Configure
Configuring App ID
Configuring Facebook Connector
- Create a new Mule Application
- Click on Global Elements tab in your main flow
- Click on Create Button
- Select Facebook under connector configuration group
- Add Facebook App ID value to consumer key text box
- Add Facebook secret key value to consumer secret text box
- Leave the scope text box empty. The default value for scope is “email,read_stream,publish_stream” which covers most of the access permissions
- Click on Oauth tab and specify domain, local port and remote port values.
A sample screen shot and XML configuration is given below.
Facebook Connector_1
Facebook Connector_2
<facebook:config-with-oauth name="Facebook" consumerKey="${ConsumerKey}" consumerSecret="${ConsumerSecret}" doc:name="Facebook"> <facebook:oauth-callback-config domain="localhost" localPort="1100" remotePort="1100" /> </facebook:config-with-oauth>
Mule Flow for Facebook Authentication
- Configure a flow as shown below
<flow name="AutorizeFacebook" doc:name="AutorizeFacebook">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="5555" doc:name="HTTP" path="facebookupdate" />
<facebook:authorize config-ref="Facebook" doc:name="Authorize" />
<choice doc:name="Choice">
<when expression="flowVars.OAuthAccessTokenId != null">
<logger message="Authorization Successful" level="INFO"
doc:name="Logger" />
<set-payload value="Facebook Authorization Successful"
doc:name="Set Payload" />
</when>
<otherwise>
<logger message="Authorization Failed" level="INFO" doc:name="Logger" />
<set-payload value="Facebook Authorization Failed"
doc:name="Set Payload" />
</otherwise>
</choice>
</flow>
- If the app authorizes in to Facebook successfully, the connector returns two flow variables to Mule ESB flow which are “_oauthVerifier” and “OAuthAccessTokenId”
- Using Choice router, we can check whether the flow received an “OAuthAccessTokenId” or not and based on the response we would be able to determine the success or failure of the Facebook authorization.
Testing and Observation
- Deploy the app
- Hit the following URL on the browser
http://localhost:1111/facebookauthorize
- Facebook will ask us to authorize the new app to connect to Facebook. This authorization will be needed only on the first time when running the application.
- Click on Okay button and we should see a message on the browser as “Facebook Authorization Successful”
- In order to publish or post a message on Facebook, we will need to submit the app for review and request for “publish_stream” access on developer app.
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 Twitter using Mule ESB
Integration with LinkedIn using Mule ESB
Integration with Dropbox using Mule ESB