Facebook SDK 7.10- Unity 2017 - Display Profile Picture
Hi, I get IGraphResult as null, hence the texture as null too. Here is the API call:
FB.API("me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayPhoto);
Here is the callback function:
void DisplayPhoto(IGraphResult result)
{
if (!string.IsNullOrEmpty(result.Error))
{
_profilePic.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2());
}
else if(result.Error == null)
{
Debug.Log("heeeeee " + result.Error);
}
}
Answer by Lewey100 · Feb 26, 2018 at 07:43 PM
Hi, I'm not sure if you fixed this issue but I have been trying to tackle it all day. You can get the direct image URL using this:
FB.API("/me/picture?redirect=false", HttpMethod.GET, ProfilePhotoCallback);
Then you can use that URL to download the image file directly. I know its a silly way of doing it considering the API used to work out the box but it'll get you your image! Here is the code below to get the image using the URL:
private void ProfilePhotoCallback (IGraphResult result)
{
if (String.IsNullOrEmpty(result.Error) && !result.Cancelled) { //if there isn't an error
IDictionary data = result.ResultDictionary["data"] as IDictionary; //create a new data dictionary
string photoURL = data["url"] as String; //add a URL field to the dictionary
StartCoroutine(fetchProfilePic(photoURL)); //Call the coroutine to download the photo
}
}
private IEnumerator fetchProfilePic (string url) {
WWW www = new WWW(url); //use the photo url to get the photo from the web
yield return www; //wait until it has downloaded
this.profilePic = www.texture; //set your profilePic Image Component's sprite to the photo
}
Hope this helped!
Answer by mibo90 · Aug 15, 2017 at 10:30 AM
Same problem here. Apparently from what I could find out so far there is no fix. We need to wait for Facebook to update the Unity SDK. It seems there are workarounds, but they involve a lot of fiddling with the request/response. There is no date set for the new Facebook SDK as of 15-Aug-2017, but I imagine soon... fingers crossed. Here's a link with more details: https://developers.facebook.com/bugs/341638962932484/
That thread has been closed by Facebook - Irritating as they have not left it open to update on a workaround?
Answer by satanas · Feb 12, 2018 at 06:40 AM
Try with a forward slash before "me":
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayPhoto);