Skip to content
Francisco Dias edited this page Aug 27, 2026 · 1 revision

Login and Permissions

Signing the user in, keeping the session fresh, and checking what the session is allowed to do.

Functions

Login and permission functions.

Structs

Login data types.



Back To Top

fb_check_permission

Checks whether the current session already holds a given permission, without going anywhere near the network. Use it before a call that needs one, so you can ask for it with fb_login rather than letting the request fail.

The answer reflects the permissions attached to the live access token, so it is only as fresh as that token - call fb_refresh_access_token first if the user may have revoked something from Facebook's own settings while your game was running.


Syntax:

fb_check_permission(permission)
Argument Type Description
permission String The permission name to check, e.g. "email".

Returns:

Boolean

true if a live token holds that permission, false otherwise (including when no user is logged in).


Example:

if (!fb_check_permission("email"))
{
    fb_login(["email"], function(_result, _login_info)
    {
        // Handle the new session here.
    });
}


Back To Top

fb_login

Starts Meta's login flow, asking the user for the permissions you list. If the Facebook app is installed the flow happens there, otherwise it falls back to a Custom Tab / web view.

Only one login can be in flight at a time - a second call while the first is still waiting on the user returns FacebookError.LoginInProgress. Passing an empty array asks for "public_profile" only.

Note

Anything beyond "public_profile", "email" and "user_friends" has to be approved by Meta through App Review before it works for anyone other than the app's own testers.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

fb_login(permissions, callback)
Argument Type Description
permissions Array of String The permissions to request, e.g. ["public_profile", "email"].
callback Function The function to call once the login completes, fails or is cancelled.

Returns:

FacebookError

FacebookError.Ok if the login was started, or NotInitialized / ActivityNull / LoginInProgress if it was rejected up front. The callback does not fire when a value other than Ok is returned.


Triggers:

Callback

Fires once, when the user finishes with Meta's login screen.

Key Type Description
result FacebookResult The login outcome. A user who backed out of the login screen
reports status as FacebookOperationStatus.Cancelled rather than as an error.
login_info FacebookLoginInfo The new session. Only present on success.

Example:

var _error = fb_login(["public_profile"], function(_result, _login_info)
{
    if (_result.success)
    {
        show_debug_message("Facebook user: " + _login_info.user_id);
        show_debug_message("Permissions: " + json_stringify(_login_info.permissions));
    }
    else if (_result.status == FacebookOperationStatus.Cancelled)
    {
        show_debug_message("Facebook login cancelled.");
    }
    else
    {
        show_debug_message("Facebook login failed: " + (_result.error_message ?? "Unknown error."));
    }
});

if (_error != FacebookError.Ok)
    show_debug_message("Facebook login could not be started (error " + string(_error) + ").");


Back To Top

fb_refresh_access_token

Asks Meta to refresh the current access token, returning an up-to-date FacebookLoginInfo - including the permission lists, which is the point of calling it: a user can revoke a permission from Facebook's own settings at any time, and only a refresh will tell you.

There is no need to call this on a timer. Meta's SDK extends a healthy token on its own; this is for the cases where you want the refreshed permission lists, or want to confirm the session is still valid after a long time in the background.

This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Callback.


Syntax:

fb_refresh_access_token(callback)
Argument Type Description
callback Function The function to call once the refresh completes or fails.

Returns:

FacebookError

FacebookError.Ok if the refresh was started, NotInitialized if the SDK is not up, or NotLoggedIn if there is no live token to refresh. The callback does not fire when a value other than Ok is returned.


Triggers:

Callback

Fires once, when Meta answers.

Key Type Description
result FacebookResult The refresh outcome.
login_info FacebookLoginInfo The refreshed session. Only present on success.

Example:

var _error = fb_refresh_access_token(function(_result, _login_info)
{
    if (!_result.success)
    {
        show_debug_message("Facebook token refresh failed: " + (_result.error_message ?? "Unknown error."));
        return;
    }

    show_debug_message("Permissions now granted: " + json_stringify(_login_info.permissions));
});


Back To Top

FacebookLoginInfo

The session payload delivered as the second argument of the fb_login and fb_refresh_access_token callbacks. Only present on success - on a failure or a cancellation the argument is undefined.

This struct is referenced by the following functions:


Member Type Description
access_token String The access token for the new session. Treat it as a credential.
user_id String The app-scoped Facebook user ID.
permissions Array of String The permissions the user actually granted.
declined_permissions Array of String The permissions the user was asked for and refused.
Asking again for a declined permission is only worth doing once you have explained why you need it.


Clone this wiki locally