To use the Facebook connector, add the <facebook.init>
element in your configuration before carrying out any other Faceboook operationsoperation. Most Graph API requests require the use of access tokens, which the app that the client application can generate by implementing Facebook Login.
The basic strategy procedure to get a user token is for the client to request access and permission via the Facebook 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 more information, refer to access tokens and how to generate them using Facebook Login.
Code Block |
---|
language | html/xml |
---|
title | init |
---|
|
<facebook.init>
<apiUrl>{$ctx:apiUrl}</apiUrl>
<apiVersion>{$ctx:apiVersion}</apiVersion>
<accessToken>{$ctx:accessToken}</accessToken>
</facebook.init> |
Properties
apiUrl
: The URL of the Facebook API (https://graph.facebook.com)
apiVersion
: Version The version of the Facebook API
accessToken
: The access token that allows making requests to the API on behalf of a user.
Obtaining an access token
This method allows you to obtain an app access tokenTo get your access token, you need to add <facebook.getAppAccessToken>
to your configuration.
Code Block |
---|
language | html/xml |
---|
title | getAppAccessToken |
---|
|
<facebook.getAppAccessToken>
<clientId>{$ctx:clientId}</clientId>
<clientSecret>{$ctx:clientSecret}</clientSecret>
</facebook.getAppAccessToken> |
Properties
clientId
: Value of your The API key given that you receive when you register your application with Facebook.clientSecret
: Value of your The client secret key given that you receive when you register your application with Facebook.
...
Following is a sample REST request for the getAppAccessToken
method.:
Code Block |
---|
language | html/xml |
---|
title | Sample request for getAppAccessToken |
---|
|
{
"apiUrl":"https://graph.facebook.com",
"clientId":"269855929842963",
"clientSecret":"6a0920b2cdf3787c993b67b9a400ad0b"
} |
Obtaining a page token
This method allows you to To obtain a page access token, you need to add <facebook.getPageAccessToken>
to your configuration.
Code Block |
---|
|
<facebook.getPageAccessToken>
<pageId>{$ctx:pageId}</pageId>
</facebook.getPageAccessToken> |
Properties
Sample request
Following is a sample REST request for the getPageAccessToken
method.:
Code Block |
---|
title | Sample request for getPageAccessToken |
---|
|
{
"apiUrl":"https://graph.facebook.com",
"apiVersion":"v2.5",
"accessToken":"CAACEdEose0cBAHr8S2hVPNpCy1DbIuGHlmwbWubyR6YSr0wxgD0ncZBYfGrRvuZC88KqChF44ZAhMRZCPUeYM6xQaHuf1pCzfAwVMrPT4GUZAIOwbc2aBRb5BD6YlA8YKBgKInK08368Xh78arj3ORrUNZCyCc",
"pageId":"102898890060274"
} |
...
<albumId>{$url:album_id}</albumId>
Since we are constructing the endpoint is constructed inside the proxy, init
does it is not need to be called for the necessary to call the init
method for multipart operations.
Sample proxy
...
to handle multipart operations
Code Block |
---|
language | html/xml |
---|
title | 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> |
...
Code Block |
---|
|
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.
...