Integration with facebook using mule esb

13
Integration with Facebook u sing Mule ESB

Transcript of Integration with facebook using mule esb

Page 2: Integration with facebook using mule esb

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.

Overview

Page 3: Integration with facebook using mule esb

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

Versions and Assumptions

Page 4: Integration with facebook using mule esb

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

Configuring Facebook App

Page 5: Integration with facebook using mule esb

A sample screen shot for the Facebook app is given below.

Page 7: Integration with facebook using mule esb

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.

Configuring Facebook Connector

Page 9: Integration with facebook using mule esb

<facebook:config-with-oauth name="Facebook"

consumerKey="${ConsumerKey}" con-sumerSecret="${ConsumerSecret}"

doc:name="Facebook"> <facebook:oauth-callback-config

domain="localhost" localPort="1100" remotePort="1100" /> </facebook:config-with-oauth>

Page 11: Integration with facebook using mule esb

<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>

Page 12: Integration with facebook using mule esb

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.

Page 13: Integration with facebook using mule esb

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.

Testing and Observation