- Home /
Facebook Friend Pictures Returning Blank on Leaderboard
I'm using Unity 2017.1.03f with Facebook SDK 7.10.
When I make the call for a player's friends list from the the API, everything else returns fine. I get their scores, their name and everything else I need...except the picture.
The picture keeps returning blank, as in a white square.
Here is my code:
using UnityEngine;
using UnityEngine.UI;
using Facebook.Unity;
using Facebook.MiniJSON;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
private void ScoresCallback(IResult result) {
RankInt = 1;
IDictionary<string, object> data = result.ResultDictionary;
List<object> scoreList = (List<object>) data["data"];
foreach (Transform child in ScrollScoreList.transform) {
GameObject.Destroy(child.gameObject);
}
foreach(object obj in scoreList) {
var entry = (Dictionary<string, object>) obj;
var user = (Dictionary<string , object>) entry ["user"];
// Debug.Log(user["name"].ToString() + " , " + entry["score"].ToString());
GameObject scorePanel;
scorePanel = Instantiate (ScoreEntryPanel) as GameObject;
scorePanel.transform.SetParent(ScrollScoreList.transform, false);
Transform FName = scorePanel.transform.Find ("FriendName");
Transform FScore = scorePanel.transform.Find ("FriendScore");
Transform FAvatar = scorePanel.transform.Find ("FriendAvatar");
Transform FRank = scorePanel.transform.Find ("RankNumber");
Text FnameText = FName.GetComponent<Text> ();
Text FscoreText = FScore.GetComponent<Text> ();
Text FrankText = FRank.GetComponent<Text>();
Image FUserAvatar = FAvatar.GetComponent<Image> ();
FnameText.text = user["name"].ToString();
FscoreText.text = entry["score"].ToString();
FrankText.text = "" + RankInt;
RankInt += 1;
FB.API (user["id"].ToString() + "/picture?width=128&height=128", HttpMethod.GET, delegate (IGraphResult picresult) {
FUserAvatar.sprite = Sprite.Create(picresult.Texture, new Rect(0,0,50,50), new Vector2 (0,0), 100);
if (picresult.Error != null) {
Debug.Log("Picture Error" + picresult.RawResult);
}
});
//ScoresDebug.text = result.RawResult;
}
}
The console is returning this: "Picture Error���� UnityEngine.Debug:Log(Object) c_AnonStorey1:<>m0(IGraphResult) (at Assets/Scripts/Facebook/FBScript.cs:267) Facebook.Unity.d_9:MoveNext() UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)"
What I have tried:
putting "https" + "://graph.facebook.com/" in front of user["id"].ToString()
"/picture?width=128&height=128&redirect=false"
FUserAvatar.overrideSprite
Two things:
You should check if the texture has problems or is null before creating the sprite.
Why do you ask for a 128x128 image if you create a sprite that's 50x50?
It was previously that way, but in many "answers" they didn't even include the error check, so I changed it to be an after thought. It returns null both ways.
It was also previously asking for a 50x50, but Facebook's scripts show it calling for a 128x128 in every example, so I gave it a shot to see if that may have been the issue. Their API has been very finicky about everything being exact.