This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Likes in Facebook



Overview

The following operations allow you to work with likes. Click an operation name to see details on how to use it. 

For a sample proxy service that illustrates how to work with likes, see Sample configuration.

OperationDescription
createLikeCreates a like.
getLikesRetrieves a list of users who have liked a resource.
deleteLikeDeletes a like.

Operation details

This section provides details on each of the operations.

Creating a like

The createLike operation creates a like for either a video, post, status, note, photo, album or comment.

createLike
<facebook.createLike>
	<resourceId>{$ctx:resourceId}</resourceId>
</facebook.createLike>
Properties
  • resourceId: The ID of the resource for which you want to create a like.

Sample request

Following is a sample REST request that can be handled by the createLike operation. 

Sample Request for createLike
{
"apiUrl":"https://graph.facebook.com",
"apiVersion":"v2.4",
"accessToken":"CAAD8biEgxBIBAOt0XA4FdFFQXg8hzVtYHdrDpeeRa1nHmCylWoOiFmZAWmDYMXnZCZC2akkuIsIM2tEXZBZC1JbhFFZAqRZBRKKvTZCfnhSpojHW0BG3nVKBOGYJCKEcNT7T6onY2poZBrZBZB0FtgZB89ZCSr2THH48eZC5xcNcTjU0QxKZAjJj8cQjebmzm8883RhbErPEF5OcLUpdwZDZD",
"resourceId":"1402049403394184"
} 

Retrieving likes

The getLikes operation retrieves a list of users who have liked a particular resource such as a video, post, status, note, photo, album or comment.

getLikes
<facebook.getLikes>
	<resourceId>{$ctx:resourceId}</resourceId>
	<fields>{$ctx:fields}</fields>
	<summary>{$ctx:summary}</summary>
</facebook.getLikes>
Properties
  • resourceId: The ID of the resource for which you want to retrieve likes.

  • fields: The fields to include in the response when retrieving likes.

  • summary: Set this to true if you want to retrieve the total number of likes for the resource.

Sample request

Following is a sample REST request that can be handled by the getLikes operation. 

Sample Request for getLikes
{
"apiUrl":"https://graph.facebook.com",
"apiVersion":"v2.4",
"accessToken":"CAAD8biEgxBIBAOt0XA4FdFFQXg8hzVtYHdrDpeeRa1nHmCylWoOiFmZAWmDYMXnZCZC2akkuIsIM2tEXZBZC1JbhFFZAqRZBRKKvTZCfnhSpojHW0BG3nVKBOGYJCKEcNT7T6onY2poZBrZBZB0FtgZB89ZCSr2THH48eZC5xcNcTjU0QxKZAjJj8cQjebmzm8883RhbErPEF5OcLUpdwZDZD",
"resourceId":"1402049403394184"
} 

Deleting a like

The deleteLike operation deletes a like from a specified resource.

deleteLike
<facebook.deleteLike>
	<resourceId>{$ctx:resourceId}</resourceId>
</facebook.deleteLike> 
Properties
  • resourceId: The ID of the resource.

Sample request

Following is a sample REST request that can be handled by the deleteLike operation.

Sample Request for deleteLike
{
"apiUrl":"https://graph.facebook.com",
"apiVersion":"v2.4",
"accessToken":"CAAD8biEgxBIBAOt0XA4FdFFQXg8hzVtYHdrDpeeRa1nHmCylWoOiFmZAWmDYMXnZCZC2akkuIsIM2tEXZBZC1JbhFFZAqRZBRKKvTZCfnhSpojHW0BG3nVKBOGYJCKEcNT7T6onY2poZBrZBZB0FtgZB89ZCSr2THH48eZC5xcNcTjU0QxKZAjJj8cQjebmzm8883RhbErPEF5OcLUpdwZDZD",
"resourceId":"1402049403394184"
} 

Sample configuration

Following is a sample proxy service that illustrates how to connect to Facebook with the init operation, and then use the createLike operation. The sample request for this proxy can be found in createLike sample request. You can use this sample as a template for using other operations in this category.

As a best practice, create a separate sequence to handle response payload errors. In the following sample, the sequence that handles errors is the faultHandlerSeq.

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="facebook_createLike"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <property name="apiUrl" expression="json-eval($.apiUrl)"/>
		 <property name="apiVersion"  expression="json-eval($.apiVersion)"/>
         <property name="accessToken" expression="json-eval($.accessToken)"/>
         <property name="resourceId" expression="json-eval($.resourceId)"/>
         <facebook.init>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
			<apiVersion>{$ctx:apiVersion}</apiVersion>
            <accessToken>{$ctx:accessToken}</accessToken>
         </facebook.init>
         <facebook.createLike>
            <resourceId>{$ctx:resourceId}</resourceId>
         </facebook.createLike>
         <respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>                                Â