Socialid.login.extendFacebookToken

From Social ID Developers
(Difference between revisions)
Jump to: navigation, search
(Created page with "== 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 htt...")
 
(Example)
 
(One intermediate revision by one user not shown)
Line 25: Line 25:
 
== API Response ==
 
== API Response ==
  
This API performs various callbacks and triggers different events.
+
This API performs various callbacks.
  
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:
+
The following callbacks passed as parameter to this API will be performed:
* [[socialid.events.onLoginSuccess]]
+
* 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.
* [[socialid.events.onLoginError]]
+
 
+
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.
 
* onUnauthorized(): the user is logged into Facebook, but has not authorized the social application.
 
* onLoggedOut(): the user is not logged into Facebook.
 
* onLoggedOut(): the user is not logged into Facebook.
Line 38: Line 34:
 
== Example ==
 
== Example ==
  
Automatically logs an user given its access token provided by Facebook Javascript SDK:
+
Automatically extends a short lived access token provided by Facebook Javascript SDK:
  
 
   var appId = 1, fbAppId = '12345';
 
   var appId = 1, fbAppId = '12345';
 
   socialid.login.init(appId);
 
   socialid.login.init(appId);
   socialid.login.automaticFacebookLogin(fbAppId, {
+
   socialid.login.extendFacebookToken(fbAppId, {
 
     onConnected: onConnected,
 
     onConnected: onConnected,
 
     onUnauthorized: onUnauthorized,
 
     onUnauthorized: onUnauthorized,
Line 49: Line 45:
  
 
   /* Facebook Login Callbacks */
 
   /* Facebook Login Callbacks */
   function onConnected(accessToken, loginStatus) {
+
   function onConnected(accessToken, response) {
     alert("You are connected to Facebook with access token: " + accessToken);
+
     alert("You are connected to Facebook.");
     if (loginStatus.status != "success") {
+
     alert("Short lived access token: " + accessToken);
        alert("There was an error logging you.");
+
    alert("Long lived access token: " + response.data.facebook_credential.access_token);
    }
+
 
   }
 
   }
 
   function onUnauthorized() {
 
   function onUnauthorized() {
Line 61: Line 56:
 
     alert("You are not logged in to Facebook.");
 
     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
 

Latest revision as of 20:03, 27 December 2016

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.");
 }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox