Facebook SDK FB.Init fails

So far I have followed this youtube tutorial but have been unable to gwt FB.Init to work.

The only thing that was different is versions:
Unity version 5.2.1f1, Facebook SDK 7.1.0

How to troubleshoot this issue?

A few things have changed. Changelog - Unity SDK - Documentation - Meta for Developers

  • FB.Login has been split into FB.LoginWithReadPermissions and FB.LoginWithPublishPermissions
  • IResult replaces FBResult

I used:

public void FBLogin()
    {
        List<string> perms = new List<string>() { "public_profile, email", "user_friends" };
        FB.LogInWithReadPermissions(perms, AuthCallBack);
    }
}

void AuthCallBack(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // AccessToken class will have session details
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            // Print current access token's User ID
            Debug.Log(aToken.UserId);
            // Print current access token's granted permissions
            foreach (string perm in aToken.Permissions) {
                Debug.Log(perm);
            }
            DealWithFBMenus(true);
        } else {
            Debug.Log("User cancelled login");
            DealWithFBMenus(false);
        }
    }

Yes I noticed these changes but I haven’t got that far since I’m already experiencing issues in fb.init.

This is what I have currently, but always getting Debug.Log(“Failed to Initialize the Facebook SDK”);
Funny thing is that this works in example scene which comes with the FB SDK

void Awake()
    {
        if (!FB.IsInitialized)
        {
            // Initialize the Facebook SDK
            FB.Init(this.InitCallback, this.OnHideUnity);
            Debug.Log("FBInit is called with appID:" + FB.AppId);
        }
        else
        {
            // Already initialized, signal an app activation App Event
            FB.ActivateApp();
        }
    }

    private void InitCallback()
    {
        if (FB.IsInitialized)
        {
            // Signal an app activation App Event
            FB.ActivateApp();
            // Continue with Facebook SDK
            // ...
            var perms = new List<string>() { "public_profile", "email", "user_friends" };
            FB.LogInWithReadPermissions(perms, AuthCallback);
        }
        else
        {
            Debug.Log("Failed to Initialize the Facebook SDK");
        }
    }

    private void OnHideUnity(bool isGameShown)
    {
        if (!isGameShown)
        {
            // Pause the game - we will need to hide
            Time.timeScale = 0;
        }
        else
        {
            // Resume the game - we're getting focus again
            Time.timeScale = 1;
        }
    }

I’ve got the same problem with FB.Init(). If You simply do the things that Facebook provides in example docs it just throughs “Failed to Initialize the Facebook SDK” so it goes to InitCallback function to else block…
Couldn’t find any solution yet. If someone reaches any results, please help the others :slight_smile:

1 Like

I’ve got the same problem. Did you solved this problem ?

Try this

from facebook bugs site:

in the FacebookGameObject " this.Initialized = true" is call after the call back “.OnInitComplete”. so if (FB.IsInitialized) always = false

public void OnInitComplete(string message)
{
this.Facebook.OnInitComplete(message);
this.Initialized = true; }

Should be

public void OnInitComplete(string message)
{ this.Initialized = true;
this.Facebook.OnInitComplete(message);
}

1 Like

@IlkoIliev thanks that did the trick and it is working now as expected

I had the same issue, but realised it was because on recently updating Unity & Facebook SDK I had lost my App ID info in the FB Settings…

Today I updated to latest Facebook SDK 7.2.0 and noticed that this issue is now fixed in sdk as well.