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 Users in Facebook
Overview
The following operations allow you to work with users. Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with users, see Sample configuration.
Operation | Description |
---|---|
createPost | Allows to create a post. |
getMutualFriends | Allows to retrieve the list of mutual friends between two people. |
getUserDetails | Allows to retrieve the details of the user. |
isFriend | Checks if the person is a friend of the user. |
publishNotification | Allows to publish the user's unread Facebook notifications. |
Operation details
This section provides details on each of the operations.
Creating a post
This method allows the users to publish a post.
<facebook.createPost> <message>{$ctx:message}</message> <link>{$ctx:link}</link> <picture>{$ctx:picture}</picture> <name>{$ctx:name}</name> <caption>{$ctx:caption}</caption> <description>{$ctx:description}</description> <actions>{$ctx:actions}</actions> <place>{$ctx:place}</place> <tags>{$ctx:tags}</tags> <privacy>{$ctx:privacy}</privacy> <objectAttachment>{$ctx:objectAttachment}</objectAttachment> </facebook.createPost>
Properties
message: The main body of the post, otherwise called the status message. Either
link
ormessage
must be supplied.link: The URL of a link to attach to the post. Either
link
ormessage
link
picture: Determines the preview image associated with the link.
name: Overwrites the title of the link preview.
caption: Overwrites the caption under the title in the link preview.
description: Overwrites the description in the link preview
actions: The action links attached to the post.
place: Page ID of a location associated with this post.
tags: Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a
place
privacy: Determines the privacy settings of the post. If not supplied, this defaults to the privacy level granted to the app in the Login Dialog. This field cannot be used to set a more open privacy setting than the one granted.
objectAttachment: Facebook ID for an existing picture in the person's photo albums to be used as the thumbnail image. The person must be the owner of the photo, and the photo cannot be part of a message attachment.
Sample request
Following is a sample REST request for the createPost method.
{ "apiUrl":"https://graph.facebook.com", "apiVersion":"v2.4", "accessToken":"CAACEdEose0cBAELbf7L36EFqHJktqfWa75sOC92i0PiZC13cEmvL4wb2b6Oaz7m7V46QydCUVPTgE7Ouxu35RloyVcrdmFnpvkyp0CJZCR0oAGc1wZAP9yN4a49O53PkA7z8QG5mJNfvKggggG8Xdbgcl1w72NMZC7L7SIqht40bmW4iAaXhTkFUO0ybOkcZD", "message":"This week is not over" }
Further illustration on link, actions and privacy is given in https://developers.facebook.com/docs/graph-api/reference/user/feed/#readfields
Related Facebook documentation:
https://developers.facebook.com/docs/graph-api/reference/user/feed/#publish
Retrieving mutual friends
The following will display the list of mutual friends the session user and the request user have in common.
<facebook.getMutualFriends> <userId>{$ctx:userId}</userId> </facebook.getMutualFriends>
Properties
userAId: The ID of this person's user account.
userBId: The ID of the user's selected friend.
Sample request
Following is a sample REST request for the getMutualFriends method.
{ "apiUrl":"https://graph.facebook.com", "apiVersion":"v2.4", "accessToken":"CAACEdEose0cBAAAQrho1OkWWT1YUZAzbOkXYq8VZBacxr7a7sWh3KwLJL7WVkwLBFUXBWAIy3G59HpWx1FWIrbSIlf2tbO6TTB4c4RCk5WkR8Llyavcze7y1obrG86e0LZAMCZAvLiNxJ8Vb6b8HBTD0TL3WRLiZBXRhYDRFli5c2gxw73Xp8pZBcUsNue5eIZD", "userId":"747051343", "fields":"" }
For further information on "fields", refer to https://developers.facebook.com/docs/graph-api/reference/user/mutualfriends#readfields.
Related Facebook documentation:
Retrieving user details
This method will retrieve details of the user. This requires the fields and connection parameters to be passed in init.
<facebook.getUserDetails/>
Sample request
Following is a sample REST request for the getUserDetails method.
{ "apiUrl":"https://graph.facebook.com", "apiVersion":"v2.4", "accessToken":"CAACEdEose0cBAPas3EqVsnzvtvEyZAPdrXEgdRRHEYEa6wZBJzupmqxJQXnxQ75EHeyg9cZBa2lOgObUpdmTTfQLqryHHjAV5bgd7njEML9uZBAaNuYl6q1KjlCteifZA9THGTRsZBZBk2LQQEaaHZCxQmUsYh3RMghs9vDGhOZC0Y8ZAdVpRl3usfCRvitQtLNHPNKOWzy59peAZDZD", "fields":"" }
For further details on "fields", refer to https://developers.facebook.com/docs/graph-api/reference/user#fields
Related Facebook documentation:
https://developers.facebook.com/docs/graph-api/reference/user#read
Determining friends
This method determines whether a person is friends with the root node user. This requires the fields parameter to be passed into init.
<facebook.isFriend> <sourceUserId>{$ctx:sourceUserId}</sourceUserId> <targetUserId>{$ctx:targetUserId}</targetUserId> </facebook.isFriend>
Properties
- sourceUserId: ID of the person to be determined.
- targetUserId: ID of the user to be checked with.
Sample request
Following is a sample REST request for the isFriend method.
{ "apiUrl":"https://graph.facebook.com", "apiVersion":"v2.4", "accessToken":"CAACEdEose0cBAAAQrho1OkWWT1YUZAzbOkXYq8VZBacxr7a7sWh3KwLJL7WVkwLBFUXBWAIy3G59HpWx1FWIrbSIlf2tbO6TTB4c4RCk5WkR8Llyavcze7y1obrG86e0LZAMCZAvLiNxJ8Vb6b8HBTD0TL3WRLiZBXRhYDRFli5c2gxw73Xp8pZBcUsNue5eIZD", "sourceUserId":"1732179422", "targetUserId":"747051343", "fields":"" }
Related Facebook documentation:
https://developers.facebook.com/docs/graph-api/reference/user/friends/#read
Publishing notification
Displays the user's unread Facebook notifications.
<facebook.publishNotification> <href>{$ctx:href}</href> <userId>{$ctx:userId}</userId> <template>{$ctx:template}</template> </facebook.publishNotification>
Properties
- href: The relative path that someone clicking on the notification will be directed to. This will be appended to the app's canvas URL.
- userId: The ID of the person's user account.
- template: The message text of the notification. This can be formatted according to special text templating. Maximum of 180 characters.
Sample request
Following is a sample REST request for the publishNotification method.
{ "apiUrl":"https://graph.facebook.com", "apiVersion":"v2.4", "accessToken":"CAAGZCMZA2ZCZBjIBAGggngSr83BQeKyZBURGscejHaGc8yI6524yDPv6lsamw2ua7Hmh13DT9YPTiM2hpJFXmXZBLlxeqtpSrmenGItIZAJmQNKkyUdnGwZACJaXu7Cyp0ZCiD4AViO5t1RTSzg8RWsVEad5mCsDfafzJ1tYYMQZARpDyMiZB3FQ4R3V7gs2j7j0igZD", "userId":"142758138512", "href":"id/team", "template":"This is app is awsome" }
Related Facebook documentation:
https://developers.facebook.com/docs/graph-api/reference/user/notifications/#publish
Sample configuration
Following is a sample proxy service that illustrates how to connect to Facebook with the init operation and use the createUserAchievement operation to Users. The sample request for this proxy can be found in createUserAchievement 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 for handling the response payload for errors. In the following sample, this sequence is "faultHandlerSeq".
<proxy xmlns="http://ws.apache.org/ns/synapse" name="facebook_createPost" 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="achievement" expression="json-eval($.achievement)"/> <facebook.init> <apiUrl>{$ctx:apiUrl}</apiUrl> <apiVersion>{$url:apiVersion}</apiVersion> <accessToken>{$ctx:accessToken}</accessToken> </facebook.init> <facebook.createUserAchievement> <achievement>{$ctx:achievement}</achievement> </facebook.createUserAchievement> <respond/> </inSequence> <outSequence> <property name="messageType" value="application/json" scope="axis2" /> <send/> </outSequence> </target> </proxy>