Facebook annoying :(

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 :frowning:

Here is my weak code:

using UnityEngine;
using System.Collections.Generic;
using Facebook.Unity;
using UnityEngine.UI;

public class FacebookLogin : MonoBehaviour
{
  public GameObject ProfileImageObject;
  private Image profileImage;

  void Awake()
  {
    if (!FB.IsInitialized)
    {
      FB.Init(InitCallback, OnHideUnity);
    }
    else
    {
      FB.ActivateApp();
    }
  }

  void Start()
  {
    profileImage = ProfileImageObject.GetComponent<Image>();
  }

  public void Login()
  {
    var perms = new List<string>() { "public_profile", "user_friends", "publish_actions" };

    FB.LogInWithPublishPermissions(perms, AuthCallback);
  }

  private void SetProfilePicture(/*AccessToken accessToken*/)
  {
      //var url = @"http://graph.facebook.com/" + accessToken.UserId + "/picture";//?access_token=" + accessToken.TokenString;
      Debug.Log("?");
      FB.API("/me/picture?type=square&height=128&width=128&access_token=" + AccessToken.CurrentAccessToken.TokenString, HttpMethod.GET, DisplayProfilePic);

      //Debug.Log("OMG!!!! :( :( :(");
      //var profilePicture = new WWW(url);
      //Debug.Log("OK GOOD SO FAR");
      //while (!profilePicture.isDone)
      //{
      //  yield return new WaitForSeconds(1);
      //}
      //Debug.Log("Download is done... ");
      //profileImage.sprite = Sprite.Create(profilePicture.texture, profileImage.sprite.rect, profileImage.sprite.pivot);
      //Debug.Log("If it crashed FU!");
  }

  private void DisplayProfilePic(IGraphResult result)
  {
    Debug.Log("DisplayProfilePic");
    if (result.Texture != null)
    {
      Debug.Log("changing pic");
      profileImage.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2());
    }
    else
    {
      Debug.Log("no result");
    }
  }

  private void AuthCallback(ILoginResult result)
  {
    if (FB.IsLoggedIn)
    {
      AccessToken.CurrentAccessToken = result.AccessToken;
      SetProfilePicture();

      Debug.Log("User logged in");
    }
    else
    {
      Debug.Log("User cancelled login");
    }
  }


  private void InitCallback()
  {
    if (FB.IsInitialized)
    {
      FB.ActivateApp();
    }
    else
    {
      Debug.Log("Failed to Initialize the Facebook SDK");
    }
  }

  private void OnHideUnity(bool isGameShown)
  {
    if (!isGameShown)
    {
      Time.timeScale = 0;
    }
    else
    {
      Time.timeScale = 1;
    }
  }
}

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 :frowning: This is the first day since using Unity that I’ve had 2-3 hours wasted on nothing :frowning:

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

bool someProperty {
     get { return someProperty; }
}
bool _someProperty;

That probably doesn’t help here, but I thought it would be better than nothing.

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.

  public void Login()
  {
    FB.LogInWithPublishPermissions(new List<string> { "publish_actions" }, AuthCallback);
    FB.LogInWithReadPermissions(new List<string> { "public_profile", "user_friends" }, AuthCallback);
  }

You can report facebook SDK bugs here.

1 Like

Thanks, I just reported it.