Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Facebook SDK FB.Init fails

Discussion in 'Editor & General Support' started by vipasane, Sep 28, 2015.

  1. vipasane

    vipasane

    Joined:
    Feb 11, 2015
    Posts:
    14
    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?
     
  2. jaiyan

    jaiyan

    Joined:
    Jun 23, 2015
    Posts:
    4
    A few things have changed. https://developers.facebook.com/docs/unity/change-log

    • FB.Login has been split into FB.LoginWithReadPermissions and FB.LoginWithPublishPermissions
    • IResult replaces FBResult
    I used:
    Code (CSharp):
    1. public void FBLogin()
    2.     {
    3.         List<string> perms = new List<string>() { "public_profile, email", "user_friends" };
    4.         FB.LogInWithReadPermissions(perms, AuthCallBack);
    5.     }
    6. }
    7.  
    8. void AuthCallBack(ILoginResult result)
    9.     {
    10.         if (FB.IsLoggedIn)
    11.         {
    12.             // AccessToken class will have session details
    13.             var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
    14.             // Print current access token's User ID
    15.             Debug.Log(aToken.UserId);
    16.             // Print current access token's granted permissions
    17.             foreach (string perm in aToken.Permissions) {
    18.                 Debug.Log(perm);
    19.             }
    20.             DealWithFBMenus(true);
    21.         } else {
    22.             Debug.Log("User cancelled login");
    23.             DealWithFBMenus(false);
    24.         }
    25.     }
     
  3. vipasane

    vipasane

    Joined:
    Feb 11, 2015
    Posts:
    14
    Yes I noticed these changes but I haven't got that far since I'm already experiencing issues in fb.init.
     
  4. vipasane

    vipasane

    Joined:
    Feb 11, 2015
    Posts:
    14
    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

    Code (CSharp):
    1.    
    2. void Awake()
    3.     {
    4.         if (!FB.IsInitialized)
    5.         {
    6.             // Initialize the Facebook SDK
    7.             FB.Init(this.InitCallback, this.OnHideUnity);
    8.             Debug.Log("FBInit is called with appID:" + FB.AppId);
    9.         }
    10.         else
    11.         {
    12.             // Already initialized, signal an app activation App Event
    13.             FB.ActivateApp();
    14.         }
    15.     }
    16.  
    17.     private void InitCallback()
    18.     {
    19.         if (FB.IsInitialized)
    20.         {
    21.             // Signal an app activation App Event
    22.             FB.ActivateApp();
    23.             // Continue with Facebook SDK
    24.             // ...
    25.             var perms = new List<string>() { "public_profile", "email", "user_friends" };
    26.             FB.LogInWithReadPermissions(perms, AuthCallback);
    27.         }
    28.         else
    29.         {
    30.             Debug.Log("Failed to Initialize the Facebook SDK");
    31.         }
    32.     }
    33.  
    34.     private void OnHideUnity(bool isGameShown)
    35.     {
    36.         if (!isGameShown)
    37.         {
    38.             // Pause the game - we will need to hide
    39.             Time.timeScale = 0;
    40.         }
    41.         else
    42.         {
    43.             // Resume the game - we're getting focus again
    44.             Time.timeScale = 1;
    45.         }
    46.     }
     
  5. skrups

    skrups

    Joined:
    Mar 28, 2014
    Posts:
    4
    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 :)
     
    carsonhui likes this.
  6. carsonhui

    carsonhui

    Joined:
    Oct 4, 2015
    Posts:
    3
    I've got the same problem. Did you solved this problem ?
     
  7. IlkoIliev

    IlkoIliev

    Joined:
    May 24, 2015
    Posts:
    2
    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);
    }
     
    Last edited: Oct 5, 2015
    vipasane likes this.
  8. vipasane

    vipasane

    Joined:
    Feb 11, 2015
    Posts:
    14
    @IlkoIliev thanks that did the trick and it is working now as expected
     
  9. CheekySax

    CheekySax

    Joined:
    Feb 21, 2014
    Posts:
    3
    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...
     
  10. vipasane

    vipasane

    Joined:
    Feb 11, 2015
    Posts:
    14
    Today I updated to latest Facebook SDK 7.2.0 and noticed that this issue is now fixed in sdk as well.