Socialid.login.automaticFacebookLogin

From Social ID Developers
Jump to: navigation, search

Contents

Description

It uses the Facebook Javascript SDK to automatically log a user in if permission has already been given to the social application.

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 the automatic Facebook login 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 method can trigger the following events:

Usage

 socialid.login.automaticFacebookLogin(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