Socialid.login.extendFacebookToken
Contents |
Description
API to automatically get and extend a Facebook token using the Facebook Javascript SDK.
It's necessary to inform your Facebook application id (check in https://developers.facebook.com/apps/) as a parameter in this API. This Facebook application id should be the same configured in the Facebook social app used in your Social Login application (check in https://app.socialidnow.com/marketing/social_apps). If you don't have your social app configured in the Social-ID platform, you should be using the default application, and this API does not work in this case. It's recommended to you create an application on Facebook platform and configure it in the Social-ID platform (see Facebook Application Settings).
This API will check the Facebook Javascript SDK for a logged and if a connected user is found it'll try to extend the short lived token for a long lived one using the Socialid.login.extendCredentials Javascript API
Usage
socialid.login.extendFacebookToken(facebookAppId, callbacks)
Parameters
facebookAppId | required | Facebook Application ID. Check your application in this page: https://developers.facebook.com/apps/. Note: use the same social app ID configured in the Social Login. | callbacks | optional | A Javascript object containing handlers for the following events: onConnected, onUnauthorized and onLoggedOut. |
---|
API Response
This API performs various callbacks.
The following callbacks passed as parameter to this API will be performed:
- onConnected(accessToken, response): the user is logged into Facebook and has authorized the social application. "accessToken" is the short lived access token provided by Facebook and "response" is the Socialid.login.extendCredentials API response which contains the long lived access token.
- onUnauthorized(): the user is logged into Facebook, but has not authorized the social application.
- onLoggedOut(): the user is not logged into Facebook.
Example
Automatically extends a short lived access token provided by Facebook Javascript SDK:
var appId = 1, fbAppId = '12345'; socialid.login.init(appId); socialid.login.extendFacebookToken(fbAppId, { onConnected: onConnected, onUnauthorized: onUnauthorized, onLoggedOut: onLoggedOut });
/* Facebook Login Callbacks */ function onConnected(accessToken, response) { alert("You are connected to Facebook."); alert("Short lived access token: " + accessToken); alert("Long lived access token: " + response.data.facebook_credential.access_token); } function onUnauthorized() { alert("You are logged in to Facebook but have not authorized the application."); } function onLoggedOut() { alert("You are not logged in to Facebook."); }