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:
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;
}
}
}