Skip to content

Initialization

Koretsky Konstantin edited this page Sep 30, 2020 · 4 revisions

Initialization flow

Before starting work, you should install the application id. It can be done via editor menu or code:

FbSettings.SetAppId("your_app_id");//example -> 1605471223039154

Next step is using permissions. As example if you need to get email, you should specify it:

if(!FbSettings.Permissions.Contains(FbPermissions.email))
    FbSettings.Permissions.Add(FbPermissions.email);

Also it can be done via editor menu too:

asdas

Sets the state of the Facebook SDK, and initializes all platform-specific data structures and behaviors. This function can only be called once during the lifetime of the object. Later calls lead to undefined behavior. Relies on properties that are set in the Unity Editor using the Facebook | Edit settings menu option

Fb.Init(() => {
    Debug.Log("Init Completed");
});

In addition after initialization will be called ActivateApp:

FbUnity.ActivateApp();

By logging app activation events, you can observe how frequently users activate your app, how much time they spend using it, and view other demographic information through Facebook Analytics for Apps.

Sending app activation events are also necessary to measure installs driven by App Ads, whose documentation you should consult for details.

Note: Does nothing on desktop apps at this time.

LogIn with permissions

Prompts the user to authorize your application using the Login Dialog appropriate to the platform. If the user is already logged in and has authorized your application, checks whether all permissions in the permissions parameter have been granted, and if not, prompts the user for any that are newly requested. In the Unity Editor, a stub function is called, which will prompt you to provide an access token from the Access Token Tool. Please note that this token will not necessarily contain the permissions you specified in FB.Login. To change this token's permissions, please use the Graph API Explorer

After initialization you should log in:

Fb.LogInWithPublishPermissions(result => {
    if (result.IsSucceeded) {
        Debug.Log("Login Succeeded");
    }
    else {
        Debug.Log("Failed to login: " + result.Error);
    }
});
Fb.LogInWithReadPermissions(result => {
    if (result.IsSucceeded) {
        Debug.Log("Login Succeeded");
    }
    else {
        Debug.Log("Failed to login: " + result.Error);
    }
});

Provided list of Facebook permissions requested from the user

Fb.LogInWithReadPermissions(FbSettings.PermissionsStringsList, result => {
    if (result.IsSucceeded) {
        Debug.Log("Login Succeeded");
    }
    else {
        Debug.Log("Failed to login: " + result.Error);
    }
});

Provided request publish permission from the user

Fb.Login(true, result => {
    if (result.IsSucceeded) {
        Debug.Log("Login Succeeded");
    }
    else {
        Debug.Log("Failed to login: " + result.Error);
    }
});

Provided list of Facebook permissions requested from the user and request publish permission from the user

Fb.Login(FbSettings.PermissionsStringsList, true, result => {
    if (result.IsSucceeded) {
        Debug.Log("Login Succeeded");
    }
    else {
        Debug.Log("Failed to login: " + result.Error);
    }
});

When you are logged in successfully you can get logged user info. After getting user info you can also get profile image

Clone this wiki locally