Our Work
200+ Enterprises across globally trust KTree for their Web & Mobile application Development needs.See What We Do
Updated today
In this sections, we will describe how to setup Webhook, to receive message from Facebook to Liferay using Webhook and how to receive message from Liferay to Facebook using Graph API.
You'll come across the following terms multiple times in this session. So here is a brief description of them:
Step 1: Create an app from Facebook developers apps portal.
Step 2: API Version, App ID, App Secret etc are displayed in Dashboard once App is created successfully.
Step 3: In settings tab, fill the information like name, email etc. and in App Domains, include the webserver’s URL.
Step 4: In reviews tab make app public and request for permissions. A notification will be received from Facebook once the review process is completed.You can also see the list of approved items.
Step 5: Make a note of app_id, which is used in further steps.
You can use the App Dashboard or the Subscriptions Edge to create new subscriptions or modify existing ones
Click on webhook tab section, select the "Pages", "User" etc base on your requirement, subscribe to the details.
When you click on "Subscribe" button, the following popup is displayed where the "Callback URL" and Token details is gathered to authenticate whether valid user and valid token are updated.
In order to receive message from Facebook to Liferay by integrating the Facebook webhook. Configure the following details in Hook elements servlet-filter and servlet-filter-mapping in liferay-hook.xml
<hook>
<servlet-filter>
<servlet-filter-name>fbwebhook</servlet-filter-name>
<servlet-filter-impl>com.facebook.hook.FacebookHook</servlet-filter-impl>
</servlet-filter>
<servlet-filter-mapping>
<servlet-filter-name>fbwebhook</servlet-filter-name>
<url-pattern>/fbwebhook</url-pattern>
</servlet-filter-mapping>
</hook>
In the above example, Servlet filters are applied if the requests from server are received that match URL patterns or match servlet names specified in your servlet filter mappings.
Here Facebook post details (text and images) are collected from request and processed to the Liferay. The below section shows you how the web content asset are used to store facebook messages.
Map<String, String[]> parametersMap = request.getParameterMap();
if (parametersMap.size() > 0)
{
//Verify Token and accept Challenge Number
String responseToClient = request.getParameter("hub.challenge");
response.getWriter().write(responseToClient);
response.getWriter().flush();
response.getWriter().close();
response.getWriter().append("Fetch-Mode").append(request.getParameter("hub.mode"));
response.getWriter().append("App Verify Token:").append(request.getParameter("hub.verify_token"));
response.getWriter().append("App Challenge No").append(request.getParameter("hub.challenge"));
//Process response information to store inside Liferay asset
}
KTree is the best offshore Liferay development company with extensive experience in Liferay Portal Development services along with Upgrade & Migration. Hire Liferay developers or Liferay development services from LiferayDeveloper.