Socialid.login.extendFacebookToken

From Social ID Developers
Revision as of 22:32, 23 December 2016 by Gabriel.prado (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 and triggers different events.

If the user is logged into Facebook and has already authorized the social application (status "connected" in the Facebook API), one of these two events will be triggered:

In addition, according to login status on Facebook, the following callbacks passed as parameter to this API will be performed:

  • onConnected(accessToken, loginStatus): the user is logged into Facebook and has authorized the social application. "accessToken" is the temporary access token provided by Facebook and "loginStatus" is the socialid.login.loginCredentials API response.
  • onUnauthorized(): the user is logged into Facebook, but has not authorized the social application.
  • onLoggedOut(): the user is not logged into Facebook.

Example

Automatically logs an user given its access token provided by Facebook Javascript SDK:

 var appId = 1, fbAppId = '12345';
 socialid.login.init(appId);
 socialid.login.automaticFacebookLogin(fbAppId, {
    onConnected: onConnected,
    onUnauthorized: onUnauthorized,
    onLoggedOut: onLoggedOut
 });
 /* Facebook Login Callbacks */
 function onConnected(accessToken, loginStatus) {
    alert("You are connected to Facebook with access token: " + accessToken);
    if (loginStatus.status != "success") {
       alert("There was an error logging you.");
    }
 }
 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.");
 }
 /* Login Events */
 socialid.events.onLoginSuccess.addHandler(function(data) {
    console.log("Website received onLoginSuccess: ", data);
 });
 socialid.events.onLoginError.addHandler(function(data) {
    console.log("Website received onLoginError: ", data);
 });

You can test the Facebook Automatic Login in our example application: https://sid-examples.herokuapp.com/social_logins/automatic_login

You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox