mule with facebook
TRANSCRIPT
![Page 1: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/1.jpg)
www.sanjeetpandey.com
MULE ESB – Facebook
![Page 2: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/2.jpg)
www.sanjeetpandey.com
Overview What is Facebook? Versions and Assumptions Configuring Facebook Configuring Facebook Connector Mule Flow for Facebook Authentication Mule Flow for retrieving logged in user details Mule Flow for publishing message in Facebook Conclusion
![Page 3: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/3.jpg)
www.sanjeetpandey.com
What is Facebook? 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
As of February 2015 Facebook reached a market capitalization of $212 Billion
Facebook is currently the most famous social networking site
![Page 4: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/4.jpg)
www.sanjeetpandey.com
Versions and Assumptions In this presentation, we are using
Facebook Connector 2.3.4 Any point Studio Mule ESB Server 3.5.2
To use this application in your project, you will need a Facebook account for testing
You will need to create a new Facebook app under Facebook developer apps to be able to communicate with your Facebook account from Mule ESB application
We will be using OAuth2 authentication to connect to Facebook using Mule ESB Facebook Connector
![Page 5: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/5.jpg)
www.sanjeetpandey.com
Configuring Facebook
Go to https://developers.facebook.com/ Click on My Apps
Click on Create a New App button and you should be given a screen as shown below
![Page 6: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/6.jpg)
www.sanjeetpandey.com
Add a unique display name, namespace and select a category. Click on Create App Id. You should get a screen similar to one
shown below
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
![Page 7: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/7.jpg)
www.sanjeetpandey.com
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 your Facebook App ID value to Consumer Key text box Add your 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 screen shot and sample XML configuration is shown in the next slide
![Page 8: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/8.jpg)
www.sanjeetpandey.com
![Page 9: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/9.jpg)
www.sanjeetpandey.com
Mule Flow for Facebook Authentication
Configure a flow as shown in the below picture
The XML configuration for this flow is given in the next slide
![Page 10: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/10.jpg)
www.sanjeetpandey.com
If the app authorizes to Facebook app successfully, the connector returns two flow variables to Mule ESB flow which are “_oauthVerifier” and “OAuthAccessTokenId”
Using Choice router, we are checking weather the flow received an “OAuthAccessTokenId” or not and based on the response we are determining the success or failure of the Facebook authorization
![Page 11: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/11.jpg)
www.sanjeetpandey.com
Deploy your app Hit the following URL on the browser
http://localhost:1111/facebookauthorize Facebook will ask you to authorize your new app to connect to
Facebook as shown below. Below screen will be prompted only first time when you run the app. Latest execution of your app will not prompt for approval.
![Page 12: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/12.jpg)
www.sanjeetpandey.com
Click on Okay button and you should see a message on the browser as “Facebook Authorization Successful”
In order to publish or post a message on Facebook, you would need to submit the app for review and request for “publish_stream” access on developer apps.
![Page 13: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/13.jpg)
www.sanjeetpandey.com
Mule Flow for retrieving logged in user details
Let’s extend the previous authorize flow and use the authentication token to retrieve the logged in user details from Facebook.
Change your Mule flow as per the given flow picture
![Page 14: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/14.jpg)
www.sanjeetpandey.com
The XML configuration for the new flow will be as shown below
![Page 15: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/15.jpg)
www.sanjeetpandey.com
In this flow, we have used another operation on Facebook connector to retrieve the logged in user details and print them on the browser using Object to JSON transformer
Deploy your app Hit the following URL on the browser
http://localhost:1111/facebookauthorize You should now see the logged in user details printed on your
browser in JSON format
![Page 16: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/16.jpg)
www.sanjeetpandey.com
Mule Flow for publishing message in Facebook
Let’s extend the previous authorize flow and use the authentication token and user details to publish a message on user’s wall.
Change your Mule flow as per the given flow picture
The XML configuration for the new flow is given in the next slide
![Page 17: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/17.jpg)
www.sanjeetpandey.com
![Page 18: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/18.jpg)
www.sanjeetpandey.com
Deploy your app Hit the following URL on the browser
http://localhost:1111/facebookauthorize You should now see a message on your browser as “Message posted on
your wall.” Check your Facebook wall and you should see a message published on
your wall as “This is a greetings from Mule ESB app” Please note that Facebook does not allow spam. Therefore, if you try
posting same message twice in a short period of time, an exception will be thrown.
![Page 19: Mule with facebook](https://reader031.vdocument.in/reader031/viewer/2022030223/588223b91a28ab52368b4901/html5/thumbnails/19.jpg)
www.sanjeetpandey.com
Conclusion Mule ESB Facebook connector provides an easy way to
connect to Facebook using Facebook OAuth2 authentication and allows performing several operations
The latest Facebook connector is simpler to use compared to the previous version of Facebook connectors
Facebook Connector is available for Mule ESB community edition