Questo documento è stato aggiornato.
La traduzione in Italiano non è ancora completa.
Aggiornamento inglese: 13 apr 2020
Aggiornamento Italiano: 10 ago 2018

Facebook Login for Mobile Games

Overview

Facebook Login is a fast and convenient way for people to create accounts and log into your game across multiple platforms. For mobile and cross-platform games, Facebook Login gives you tools to personalize in-game experiences, re-engage lapsed players, and sync game progress across platforms.

This guide explains some common uses of Facebook Login in mobile games. For full details of implementing Facebook Login on mobile platforms, see the following SDK guide docs:

Easy Login and Cross Platform Support

Facebook Login helps players play seamlessly across multiple platforms. Players can quickly create an account in your game without having to set (and likely later forget) a password. This simple experience leads to higher conversion. Once someone has created an account on one platform, they can log into your app - often with a single click - on all your other platforms. Facebook Login is available on iOS, Android, Web, Windows Phone, desktop apps and Unity.

When a person uses Facebook Login in an app, they are represented by a user ID that is consistent across platforms. This ID can be used to synchronize gameplay and game state across multiple platform versions of the same game.

Implementing Facebook Login is possible in just a few lines of code. See below for examples on iOS and Android.

iOS

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
  logInWithReadPermissions: @[@"public_profile", @"email"]
        fromViewController:self
                   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
  if (error) { 
    NSLog(@"Process error");
  } else if (result.isCancelled) {
    NSLog(@"Cancelled");
  } else {
    NSLog(@"Logged in");
  }
}];

Android

LoginManager.getInstance().registerCallback(callbackManager,
        new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // success
            }

            @Override
            public void onCancel() {
                 // cancel
            }

            @Override
            public void onError(FacebookException exception) {
                 // error
            }
});

LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));

Read More: Cross Platform Best Practices

Adding Social Features

Facebook Login lets you access information about your players such as their email address, profile picture, first name and surname, which allows you to personalise the gameplay experience for them.

Playing with Friends

Facebook Login enables your players to see which of their friends are also playing the game, allowing you to show how they're progressing in relation to their friends. For example, you can include a leaderboard, showing the names and profile pictures of a player's friends who also play the game. This kind of friend presence can increase engagement and encourage competition in your game.

To enable showing a player's friends' progress in-game, you'll need to ask your players for the user_friends permission, which requires submitting your game for app review.

Read More: Scores & Achievements, Login Permissions

Sharing

Take a look at the Sharing for Games guide for full details on the sharing options available, including sharing via Dialogs, which doesn't require Facebook Login.

Supporting Game Requests

By including Facebook Login in your game, you'll be able to implement Game Requests as a way to enable your players to interact with and re-engage their friends, as well as inviting new players to play your game.

Read More: Game Requests

Best Practices

There are some specific challenges faced by mobile game developers when implementing key Facebook features. Please read the Mobile Best Practices guide, which shows some best practice implementations of Facebook Login as seen in successful mobile games, and will help you avoid common mistakes when implementing features built on Facebook Login.

Read more: Mobile Best Practices