integrate facebook using mule esb

20
www.sanjeetpandey.com www.sanjeetpandey.com Prepared by – Sanjeet Pandey Integrate Facebook using Mule ESB

Upload: sanjeet-pandey

Post on 13-Aug-2015

113 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Integrate facebook using mule esb

www.sanjeetpandey.com

www.sanjeetpandey.com

Prepared by – Sanjeet Pandey

Integrate Facebook using Mule ESB

Page 2: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

www.sanjeetpandey.com

Page 9: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

www.sanjeetpandey.com

The XML configuration for the new flow will be as shown below

Page 15: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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: Integrate facebook using mule esb

www.sanjeetpandey.com

Page 18: Integrate facebook using mule esb

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: Integrate facebook using mule esb

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

Page 20: Integrate facebook using mule esb

www.sanjeetpandey.com 20