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. Dismiss Notice

Facebook annoying :(

Discussion in 'Editor & General Support' started by dehdar, Dec 11, 2016.

  1. dehdar

    dehdar

    Joined:
    Sep 1, 2016
    Posts:
    51
    Sorry, I'm not sure where else to post this...

    I've added the facebook SDK v7.9 to a new project.
    After setting everything up, I can run the examples projects smoothly on my android phone.

    I then made a new scene, where I log the user in. This works fine.
    But when I download the user's profile picture and attempt to display it, my app crashes.

    Annoying facts.

    adb logcat -s Unity doesn't show the error, nor does it show any other logs when my app crash (it will show logs, if I remove the code where I download the user picture).

    And even worse is, everything works perfectly fine if I run my app in the editor. It only crashes in android. So I'm puzzled what to do... with no logs, no nothing :(

    Here is my weak code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using Facebook.Unity;
    4. using UnityEngine.UI;
    5.  
    6. public class FacebookLogin : MonoBehaviour
    7. {
    8.   public GameObject ProfileImageObject;
    9.   private Image profileImage;
    10.  
    11.   void Awake()
    12.   {
    13.     if (!FB.IsInitialized)
    14.     {
    15.       FB.Init(InitCallback, OnHideUnity);
    16.     }
    17.     else
    18.     {
    19.       FB.ActivateApp();
    20.     }
    21.   }
    22.  
    23.   void Start()
    24.   {
    25.     profileImage = ProfileImageObject.GetComponent<Image>();
    26.   }
    27.  
    28.   public void Login()
    29.   {
    30.     var perms = new List<string>() { "public_profile", "user_friends", "publish_actions" };
    31.  
    32.     FB.LogInWithPublishPermissions(perms, AuthCallback);
    33.   }
    34.  
    35.   private void SetProfilePicture(/*AccessToken accessToken*/)
    36.   {
    37.       //var url = @"http://graph.facebook.com/" + accessToken.UserId + "/picture";//?access_token=" + accessToken.TokenString;
    38.       Debug.Log("?");
    39.       FB.API("/me/picture?type=square&height=128&width=128&access_token=" + AccessToken.CurrentAccessToken.TokenString, HttpMethod.GET, DisplayProfilePic);
    40.  
    41.       //Debug.Log("OMG!!!! :( :( :(");
    42.       //var profilePicture = new WWW(url);
    43.       //Debug.Log("OK GOOD SO FAR");
    44.       //while (!profilePicture.isDone)
    45.       //{
    46.       //  yield return new WaitForSeconds(1);
    47.       //}
    48.       //Debug.Log("Download is done... ");
    49.       //profileImage.sprite = Sprite.Create(profilePicture.texture, profileImage.sprite.rect, profileImage.sprite.pivot);
    50.       //Debug.Log("If it crashed FU!");
    51.   }
    52.  
    53.   private void DisplayProfilePic(IGraphResult result)
    54.   {
    55.     Debug.Log("DisplayProfilePic");
    56.     if (result.Texture != null)
    57.     {
    58.       Debug.Log("changing pic");
    59.       profileImage.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2());
    60.     }
    61.     else
    62.     {
    63.       Debug.Log("no result");
    64.     }
    65.   }
    66.  
    67.   private void AuthCallback(ILoginResult result)
    68.   {
    69.     if (FB.IsLoggedIn)
    70.     {
    71.       AccessToken.CurrentAccessToken = result.AccessToken;
    72.       SetProfilePicture();
    73.  
    74.       Debug.Log("User logged in");
    75.     }
    76.     else
    77.     {
    78.       Debug.Log("User cancelled login");
    79.     }
    80.   }
    81.  
    82.  
    83.   private void InitCallback()
    84.   {
    85.     if (FB.IsInitialized)
    86.     {
    87.       FB.ActivateApp();
    88.     }
    89.     else
    90.     {
    91.       Debug.Log("Failed to Initialize the Facebook SDK");
    92.     }
    93.   }
    94.  
    95.   private void OnHideUnity(bool isGameShown)
    96.   {
    97.     if (!isGameShown)
    98.     {
    99.       Time.timeScale = 0;
    100.     }
    101.     else
    102.     {
    103.       Time.timeScale = 1;
    104.     }
    105.   }
    106. }
     
  2. dehdar

    dehdar

    Joined:
    Sep 1, 2016
    Posts:
    51
    I modified the code a bit. I cleaned up line 71, which is senseless (I was desperate and going out of my mind). And then I removed request for publish_actions and modified login to readonly mode. Wollah it worked... Still not satisfied as the log information was totally absent :( This is the first day since using Unity that I've had 2-3 hours wasted on nothing :(
     
  3. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    562
    In my experience, up until now, the only cause of a crash that does *not* report an error is a property that references itself.

    So for example

    Code (CSharp):
    1. bool someProperty {
    2.      get { return someProperty; }
    3. }
    4. bool _someProperty;
    That probably doesn't help here, but I thought it would be better than nothing.
     
  4. dehdar

    dehdar

    Joined:
    Sep 1, 2016
    Posts:
    51
    What caused the error was the login function.

    It only works if I call login twice and place the "scopes/permissions" where it's appropriate. Poor facebook interface in my opinion... but now it works. If I change it back I don't get any logs at all and my app crashes again.

    Code (CSharp):
    1.   public void Login()
    2.   {
    3.     FB.LogInWithPublishPermissions(new List<string> { "publish_actions" }, AuthCallback);
    4.     FB.LogInWithReadPermissions(new List<string> { "public_profile", "user_friends" }, AuthCallback);
    5.   }
     
  5. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    You can report facebook SDK bugs here.
     
    dehdar likes this.
  6. dehdar

    dehdar

    Joined:
    Sep 1, 2016
    Posts:
    51
    Thanks, I just reported it.