Skip to content

General

Francisco Dias edited this page Aug 5, 2026 · 9 revisions

General

Availability, sign-in/authentication, and server-side access - plus the shared PlayServicesResult envelope and PlayServicesError codes every other module's functions use.

Functions

Availability and authentication.

Structs

The shared result envelope used across every module.

Constants

This module includes a set of predefined constants that can be utilized for various purposes. Browse through the available constants to find values relevant to your needs and enhance the efficiency of your code.



Back To Top

play_services_is_available

Checks whether Google Play Services is installed and up to date on the current device. Call this before using any other function in this extension.


Syntax:

play_services_is_available()

Returns:

Boolean

true if Google Play Services is available.


Example:

if (play_services_is_available())
    play_services_sign_in(sign_in_callback);


Back To Top

play_services_sign_in

Manually requests that the game sign in with Play Games Services.

Note

A sign-in attempt is made automatically when the game starts. Games only need to call this manually if the automatic sign-in attempt failed, or to re-prompt after a manual sign-out.

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:

play_services_sign_in(callback)
Argument Type Description
callback Function The function to call once the sign-in attempt completes.

Returns:

PlayServicesError

PlayServicesError.Ok if the request was accepted, PlayServicesError.ActivityNull otherwise.


Triggers:

Callback

Fires once, when the sign-in attempt completes.

Key Type Description
status PlayServicesResult The sign-in request's outcome. Note status.success can
be true even when is_authenticated is false - the request itself completed, but the player
chose not to authenticate.
is_authenticated Boolean Whether the player is authenticated after this attempt.

Example:

play_services_sign_in(function(_status, _is_authenticated)
{
    if (_status.success && _is_authenticated)
        show_debug_message("Signed in to Google Play Games");
});


Back To Top

play_services_is_authenticated

Queries Google Play Games Services for the current sign-in/authentication status.

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:

play_services_is_authenticated(callback)
Argument Type Description
callback Function The function to call once the query completes.

Returns:

PlayServicesError

PlayServicesError.Ok if the request was accepted, PlayServicesError.ActivityNull otherwise.


Triggers:

Callback

Fires once, when the query completes.

Key Type Description
status PlayServicesResult The query's outcome.
is_authenticated Boolean Whether the player is currently authenticated.

Example:

play_services_is_authenticated(function(_status, _is_authenticated)
{
    if (_status.success && !_is_authenticated)
        play_services_sign_in(sign_in_callback);
});


Back To Top

play_services_request_server_side_access

Requests server-side access to Play Games Services for the currently signed-in player - necessary for a game backend that needs to authenticate the player independently. Returns an authorization code your server can exchange for an access token (and, if force_refresh_token is true, a refresh token as well).

A refresh token lets your server keep requesting new access tokens while the player isn't actively playing; refresh tokens are only issued for players who have auto sign-in enabled.

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:

play_services_request_server_side_access(server_client_id, force_refresh_token, callback)
Argument Type Description
server_client_id String The OAuth 2.0 web client ID of the server that performs the
authorization code exchange.
force_refresh_token Boolean Whether to also request a refresh token when the authorization
code is exchanged.
callback Function The function to call once the request completes.

Returns:

PlayServicesError

PlayServicesError.Ok if the request was accepted, PlayServicesError.NotAuthenticated or PlayServicesError.ActivityNull otherwise.


Triggers:

Callback

Fires once, when the request completes or fails.

Key Type Description
status PlayServicesResult The request's outcome.
auth_code String The authorization code, to be exchanged by your server. Only present
on success.

Example:

play_services_request_server_side_access("your-server-client-id.apps.googleusercontent.com", false,
    function(_status, _auth_code = undefined)
    {
        if (_status.success)
        {
            // send _auth_code to your backend to exchange for an access token
        }
    });


Back To Top

PlayServicesError

The synchronous pre-flight return code every play_services_* function reports before the underlying Google Play Games call is ever attempted. Ok means the call was accepted and, for functions that take a callback, that callback will fire once the real async result is known; anything else means the callback never fires at all for that invocation.

These constants are referenced by the following functions:


Member Description
Ok The call was accepted.
NotAuthenticated The player is not authenticated. Call play_services_sign_in or
play_services_is_authenticated first.
ActivityNull The game's activity is not available yet (too early in the app lifecycle).
InvalidArgument An argument was invalid for the current state (e.g. a saved-game slot name
that hasn't been opened, or a friends page requested before the first page was loaded).


Back To Top

macros

Shared limits enforced by the Google Play Games Services API. Values outside these ranges are silently clamped (with a logcat warning), not rejected.


Member Description
PLAY_SERVICES_MAX_FRIENDS_PAGE_SIZE (value: '25')
PLAY_SERVICES_MAX_LEADERBOARD_RESULTS (value: '25')
PLAY_SERVICES_MIN_PAGE_SIZE (value: '1')


Back To Top

PlayServicesResult

The uniform success/failure envelope delivered as the first argument to every async callback in this extension. The real payload (if any) always rides as further, separate positional arguments to callback.call(status, data...) - never bundled into this struct.

This struct is referenced by the following functions:


Member Type Description
success Boolean Whether the operation succeeded.
error String The error message on failure; an empty string on success.


Clone this wiki locally