- Home /
Error facebook profile picture
Now trying to put the image of the profile of facebook in the ranking of my game.
Watching a tutorial (it's my first project) I wrote this script
public void QueryScores()
{
FB.API ("/app/scores?fields=score,user.limit(30)", Facebook.HttpMethod.GET, ScoresCallback);
}
private void ScoresCallback (FBResult result)
{
Debug.Log ("Scores callback" + result.Text);
scoresList = Util.DeserializeScores (result.Text);
foreach(Transform child in ScoreScrollList.transform)
{
GameObject.Destroy (child.gameObject);
}
foreach(object score in scoresList)
{
var entry = (Dictionary<string,object>) score;
var user = (Dictionary<string,object>) entry["user"];
GameObject ScorePanel;
ScorePanel = Instantiate (ScoreEntryPanel) as GameObject;
ScorePanel.transform.parent = ScoreScrollList.transform;
Transform ThisScoreScore = ScorePanel.transform.Find("Friend Score");
Text ScoreScore = ThisScoreScore.GetComponent<Text>();
ScoreScore.text = entry["score"].ToString ();
Transform TheUserAvatar = ScorePanel.transform.Find ("Friend Avatar");
Image UserAvatar = TheUserAvatar.GetComponent<Image>();
FB.API (Util.GetPictureURL(user["id"].ToString (), 128,128), Facebook.HttpMethod.GET, delegate(FBResult pictureResult){
if(pictureResult.Error != null) // if there was an error
{
Debug.Log (pictureResult.Error);
}
else // if everything was fine
{
UserAvatar.sprite = Sprite.Create (pictureResult.Texture, new Rect(0,0,128,128), new Vector2(0,0));
}
});
}
}
This is the error that gives me and the outcome of the script
Is there anyone who might have no idea how to solve?
Thanks in advance to those who will respond
Update: I'm not from the error, but can not download the profile picture, change to become a red question mark
Answer by zzzzzz789 · Feb 23, 2015 at 09:27 PM
The 'pictureResult.Texture' will not be auto populated with the fetched image from the Facebook. You will need to download the image separately. The URL of the picture is contained in the pictureResult.Text. These results are JSON formatted, so you will need to deserialize the URL prior to making a WWW call to download the image.
For example, here is code with no error handling: http://pastebin.com/R5v5XeAz
Yes, it works! But I'm wondering why in the tutorial everything worked perfectly with the code that I had, anyway thanks for the answer!