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/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

To use the Facebook connector, add the <facebook.init> element in your configuration before any other Faceboook operations. Most Graph API requests require the use of access tokens, which the app can generate by implementing Facebook Login.

The basic strategy to get a user token is for the client to request access and permission via the Login dialog. After the user is authenticated, the user is redirected to the user consent dialog. On completion of consent, the access token is returned to the client. For further information, refer to access tokens and how to generate them using Facebook Login.

init
<facebook.init>
	<apiUrl>{$ctx:apiUrl}</apiUrl>
	<apiVersion>{$ctx:apiVersion}</apiVersion>
	<accessToken>{$ctx:accessToken}</accessToken>
</facebook.init>
Properties
  • apiUrl: URL of the Facebook API (https://graph.facebook.com)

  • apiVersion: Version of the Facebook API

  • accessToken: The access token allows making requests to the API on behalf of a user.

Obtaining an access token

This method allows you to obtain an app access token.

getAppAccessToken
<facebook.getAppAccessToken>
	<clientId>{$ctx:clientId}</clientId>
	<clientSecret>{$ctx:clientSecret}</clientSecret>
</facebook.getAppAccessToken>                                
Properties
  • clientId: Value of your API key given when you register your application with Facebook.
  • clientSecret: Value of your secret key given when you register your application with Facebook.
Sample request

Following is a sample REST request for the getAppAccessToken method.

Sample request for getAppAccessToken
{
	"apiUrl":"https://graph.facebook.com",
	"clientId":"269855929842963",
	"clientSecret":"6a0920b2cdf3787c993b67b9a400ad0b"
}

Obtaining page token

This method allows you to obtain page access token.

getPageAccessToken
<facebook.getPageAccessToken>
	<pageId>{$ctx:pageId}</pageId>
</facebook.getPageAccessToken>                                
Properties
  • pageId: ID of your Facebook page.

Sample request

Following is a sample REST request for the getPageAccessToken method.

Sample request for getPageAccessToken
{
	"apiUrl":"https://graph.facebook.com",
 	"apiVersion":"v2.5",
	"accessToken":"CAACEdEose0cBAHr8S2hVPNpCy1DbIuGHlmwbWubyR6YSr0wxgD0ncZBYfGrRvuZC88KqChF44ZAhMRZCPUeYM6xQaHuf1pCzfAwVMrPT4GUZAIOwbc2aBRb5BD6YlA8YKBgKInK08368Xh78arj3ORrUNZCyCc",
	"pageId":"102898890060274"
}

Multipart processing

With the current features of the ESB (version 4.8.1), the multipart/form-data received cannot be processed inside the ESB. Hence, the ESB should be in a content unaware status, which you can achieve using a pass-through proxy, and the user must build the message from the client end and send it to the proxy. Additional parameters such as albumId, photoId, pageId, etc. are to be sent in the form of a URL parameter. These parameters can be retrieved from this URL and handled in the proxy. For example, if the album ID needs to be retrieved from this URL, then it is called by:

<albumId>{$url:album_id}</albumId>

Since we are constructing the endpoint inside the proxy, init does not need to be called for the multipart operations.

Sample proxy for handling multipart
postPhotoToAlbum
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="facebook_postPhotoToAlbum"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <facebook.postPhotoToAlbum>
            <albumId>{$url:album_id}</albumId>
			<apiUrl>https://graph.facebook.com</apiUrl>
			<apiVersion>{$url:apiVersion}</apiVersion>
			<accessToken>{$url:accessToken}</accessToken>
         </facebook.postPhotoToAlbum>
         <respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
Sample request (Curl)
curl -X POST \
    -d "source=%7Bimage-data%7D" \
       http://localhost:8280/services/facebook_postPhotoToAlbum/?album_id=1403293536601941

Additional information

 Ensure that the following Axis2 configurations are added and enabled in the <ESB_HOME>\repository\conf\axis2\axis2.xml file.

Required message formatters
messageFormatters
<messageFormatter contentType="multipart/form-data" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
Required message builders
messageBuilders
<messageBuilder contentType="multipart/form-data" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

The following topics describe how to perform various operations with the Facebook connector:

  • No labels