Socialid.login.automaticFacebookLogin

From Social ID Developers
(Difference between revisions)
Jump to: navigation, search
(Description)
(Description)
 
(14 intermediate revisions by one user not shown)
Line 1: Line 1:
 
== Description ==
 
== Description ==
  
Usa o Facebook SDK Javascript para tentar automaticamente logar o usuário caso já tenha sido dada permissão à aplicação social.
+
It uses the Facebook Javascript SDK to automatically log a user in if permission has already been given to the social application.
  
Nesta API é necessário passar como parâmetro o id da sua aplicação no Facebook (consulte em https://developers.facebook.com/apps/). Este id deve ser o mesmo configurado na aplicação social do seu Social Login (consulte em https://app.socialidnow.com/marketing/social_apps). Caso você não tenha uma aplicação social cadastrada na plataforma do Social-ID, você deve estar usando a aplicação padrão, neste caso não será possível usar esta API de login automático pelo Facebook. É recomendado que você crie uma nova aplicação no Facebook e configure-a na plataforma do Social-ID. Consulte as [[Facebook Application Settings | dicas de configuração de uma aplicação no Facebook]].
+
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]]).
  
O uso deste método pode disparar os eventos:
+
This method can trigger the following events:
 
* [[socialid.events.onLoginSuccess]]
 
* [[socialid.events.onLoginSuccess]]
 
* [[socialid.events.onLoginError]]
 
* [[socialid.events.onLoginError]]
Line 17: Line 17:
 
{|
 
{|
 
! align="left" width="200px" | facebookAppId
 
! align="left" width="200px" | facebookAppId
| width="200px" | obrigatório
+
| width="200px" | required
| App ID da aplicação do Facebook. Consule sua aplicação aqui: https://developers.facebook.com/apps/. Nota: use o mesmo ID da aplicação social cadastrada no Social Login.
+
| 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.
 
|+
 
|+
 
! align="left" width="200px" | callbacks
 
! align="left" width="200px" | callbacks
| width="200px" | opcional
+
| width="200px" | optional
| Um objeto contendo handlers para 3 tipos de eventos: onConnected, onUnauthorized e/ou onLoggedOut.
+
| A Javascript object containing handlers for the following events: onConnected, onUnauthorized and onLoggedOut.
 
|}
 
|}
  
 
== API Response ==
 
== API Response ==
  
Esta API executa diferentes callbacks ou dispara diferentes eventos.
+
This API performs various callbacks and triggers different events.
  
Caso o usuário esteja logado no Facebook e já tenha autorizado sua aplicação social (status "connected" na API do Facebook), um destes dois eventos será disparado:
+
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:
 
* [[socialid.events.onLoginSuccess]]
 
* [[socialid.events.onLoginSuccess]]
 
* [[socialid.events.onLoginError]]
 
* [[socialid.events.onLoginError]]
  
Além disso, serão executados os callbacks passados como parâmetro nesta API, de acordo com o status do login no Facebook:
+
In addition, according to login status on Facebook, the following callbacks passed as parameter to this API will be performed:
* onConnected(accessToken)
+
* 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()
+
* onUnauthorized(): the user is logged into Facebook, but has not authorized the social application.
* onLoggedOut()
+
* onLoggedOut(): the user is not logged into Facebook.
  
 
== Example ==
 
== Example ==
  
Loga um usuário na sessão atual dado seu access token do Facebook:
+
Automatically logs an user given its access token provided by Facebook Javascript SDK:
  
 
   var appId = 1, fbAppId = '12345';
 
   var appId = 1, fbAppId = '12345';
Line 51: Line 51:
  
 
   /* Facebook Login Callbacks */
 
   /* Facebook Login Callbacks */
   function onConnected(accessToken) {
+
   function onConnected(accessToken, loginStatus) {
     alert("You were automatically logged in with access token: " + accessToken);
+
     alert("You are connected to Facebook with access token: " + accessToken);
 +
    if (loginStatus.status != "success") {
 +
        alert("There was an error logging you.");
 +
    }
 
   }
 
   }
 
   function onUnauthorized() {
 
   function onUnauthorized() {
Line 69: Line 72:
 
   });
 
   });
  
Teste o login automático em nossa aplicação de exemplo: https://sid-examples.herokuapp.com/social_logins/automatic_login
+
You can test the Facebook Automatic Login in our example application: https://sid-examples.herokuapp.com/social_logins/automatic_login
  
Teste as APIs em nosso playground: https://sid-examples.herokuapp.com/social_logins/playground
+
You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground

Latest revision as of 14:16, 22 December 2016

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