Search Unity

Facebook Leaderboard problem

Discussion in 'Scripting' started by Reymus, Oct 8, 2015.

  1. Reymus

    Reymus

    Joined:
    Apr 27, 2015
    Posts:
    44
    hi there.

    I'm working in Unity 5.2, and have had a problem I haven't been able to solve. I followed the various tutorials on Facebook integration, and have gone over them multiple times to make sure I didn't miss a semi-colon or something.

    My problem with the leaderboard is that it will only display my own score, and not the scores of my Facebook friends that also play my game. When I click the High Scores button, it displays a panel that *should* pull the top 10 scores on my friends list, but all it does is display my own, pulled from Facebook.

    Here is the code. I don't see where my error is, so hopefully you can see what I'm missing

    Code (CSharp):
    1. public void QueryScores()
    2.     {
    3.         highScoresPanel.SetActive (true);
    4.         FB.API ("app/scores?fields=score,user.limit(10)", Facebook.HttpMethod.GET, ScoresCallback);
    5.     }
    6.  
    7.     public void ScoresCallback(FBResult result)
    8.     {
    9.  
    10.  
    11.         Debug.Log ("Scores Callback: " + result.Text);
    12.  
    13.  
    14.         scoresList = Util.DeserializeScores (result.Text);
    15.  
    16.         foreach (Transform child in ScoreScrollList.transform)
    17.         {
    18.             GameObject.Destroy (child.gameObject);
    19.         }
    20.  
    21.         foreach (object score in scoresList) {
    22.             var entry = (Dictionary<string, object>) score;
    23.             var user = (Dictionary<string, object>) entry["user"];
    24.  
    25.  
    26.  
    27.             GameObject ScorePanel;
    28.             ScorePanel = Instantiate (ScoreEntryPanel) as GameObject;
    29.  
    30.             ScorePanel.transform.parent = ScoreScrollList.transform;
    31.             ScorePanel.transform.localScale = new Vector2(1,1);
    32.  
    33.             Transform ThisScoreName = ScorePanel.transform.Find ("FriendName");
    34.             Transform ThisScoreScore = ScorePanel.transform.Find ("FriendScore");
    35.             Text ScoreName = ThisScoreName.GetComponent<Text>();
    36.             Text ScoreScore = ThisScoreScore.GetComponent<Text>();
    37.  
    38.             ScoreName.text = user["name"].ToString();
    39.             ScoreScore.text = entry["score"].ToString();
    40.  
    41.             Transform TheUserAvatar = ScorePanel.transform.Find("FriendAvatar");
    42.             Image UserAvatar = TheUserAvatar.GetComponent<Image>();
    43.  
    44.             FB.API (Util.GetPictureURL(user["id"].ToString(), 128, 128), Facebook.HttpMethod.GET, delegate(FBResult pictureResult) {
    45.                 if (pictureResult.Error != null)
    46.                 {
    47.                     Debug.Log (pictureResult.Error);
    48.                 }
    49.                 else
    50.                 {
    51.                     UserAvatar.sprite = Sprite.Create (pictureResult.Texture, new Rect(0,0,128,128), new Vector2(0,0));
    52.                 }
    53.             });
    54.  
    55.         }
    56.     }