Social - Javascript API

Enable the social Javascript API

To enable Social.js, simply include the script right after the opening <body> tag:

{% include 'social/js/' %}

This will automatically load up the proper config and javascript files that you need for the API to work.


The most basic call you can perform is social.accept() which will prompt the user to login with the platform specified in the application settings (typically Facebook). This method takes three parameters: on accept, on deny, permissions (scope).

{function|string} [callback_success] A function to call or url to redirect to if accept is successful. If nothing is given, the user will be redirected based on the social.conf.ini / facebook_success_redirect setting. If you use the function here, you will get passed an object with these keys: status (‘ok’), facebookuser (the FacebookUser id), user (the User id), redirect (a redirect url if one is applicable). As a second parameter you will get the original Facebook auth response object.
{function|string} [callback_failed] A function to call or url to redirect to when the authentication fails – response object is passed. If not given, nothing will happen.
{string} [scope] The permissions scope separated by commas. Defaults to the social.conf.ini / facebook_scope setting. See here for Facebook’s permissions.

Calling social.accept() will display popup windows, so you will need to take care of popup blockers. If you cannot solve this for some reason (should be very rare!), you can always revert to the server-side, non-javascript login flow.


You can use FB.api() calls once social.accept() has run successfully. Here’s an example usage:

    // User not yet registered
    FB.api('/me', {}, function(r){
      // Set fields based on response
Outlast Web & Mobile Development (c) 2023 | Privacy Policy |