Facebook Leaderboard not showing friend scores

Hi all.

I followed the tutorial on setting up the Facebook Scores API that Greyzoned spelled out on YouTube, and had no trouble setting it up. When I use test users, the test users can see each other’s scores. I then submitted a request to Facebook to allow publish_actions, which was then approved. Now, all of my users are able to see their own scores posted on a leaderboard, but it doesn’t show the scores of anybody else on their friend list, as I understand it should.

I’m sure I’m missing something, but I can’t for the life of me figure out what.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

public class FBMain : MonoBehaviour {

    public GameObject FBLoggedIn;
    public GameObject FBNotLoggedIn;
    public GameObject ScoreEntryPanel;
    public GameObject ScoreScrollList;
    public GameObject highScoresPanel;

    public Text HighScoreText;

    private Dictionary<string, string> profile =null;

    public GameController gameController;

    private List<object> scoresList = null;

    private List<object> myScore = null;

    public int myHighScore;

    public void Start()
    {
        if (FB.IsLoggedIn) {



            FB.API ("/me/scores", Facebook.HttpMethod.GET, delegate(FBResult result) {
                if (result == null) {
                    HighScoreText.text = "High Score: 0";
                } else {


                    myScore = Util.DeserializeScores (result.Text);
                    Debug.Log (result.Text);

                    foreach (object score in myScore) {
                        var entry = (Dictionary<string, object>)score;
               
                        Debug.Log(score);
                        HighScoreText.text = "High Score: " + entry ["score"].ToString ();
               
                        myHighScore = int.Parse (entry ["score"].ToString ());

                    }
                }
            });
        } else
        {
            HighScoreText.text = "High Score Unknown";
        }
    }

    void Awake()
    {
        FB.Init (SetInit, OnHideUnity);

    }

    private void SetInit()
    {
        Debug.Log ("FB Init Done.");

        if (FB.IsLoggedIn) {
            Debug.Log("FB Logged In");
            DealWithFBMenus(true);
        } else {
            DealWithFBMenus(false);
        }
    }

    private void OnHideUnity(bool isGameShown)
    {
        if (!isGameShown) {
            Time.timeScale = 0;
        } else {
            Time.timeScale = 1;
        }
    }

    public void FBLogin()
    {
        FB.Login ("email,publish_actions",AuthCallback);


           
    }

    void AuthCallback (FBResult result)
    {
        if (FB.IsLoggedIn) {
            Debug.Log ("FB Login worked");
            DealWithFBMenus(true);
        } else {
            Debug.Log ("FB Login Failed");
            DealWithFBMenus(false);
        }
    }

    void DealWithFBMenus(bool isLoggedIn)
    {
        if (isLoggedIn) {
            FBLoggedIn.SetActive(true);
            FBNotLoggedIn.SetActive (false);





        } else {
            FBLoggedIn.SetActive(false);
            FBNotLoggedIn.SetActive (true);
        }
    }



    public void FBShare()
    {
        GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
        if (gameControllerObject != null) {
            gameController = gameControllerObject.GetComponent <GameController> ();
        }
        if (gameController == null) {
            Debug.Log ("Cannot find 'GameController' script");
        }

        FB.Feed (
            linkCaption: "I just got a score of " + gameControllerObject.GetComponent<GameController>().score + " in Crystal Cracker! Can you beat me?",
            linkName: "Play Crystal Cracker Now",
            link: "http://roamsoftstudios.com/crystalcracker",
            picture: "http://roamsoftstudios.com/wp-content/uploads/2015/05/crystalcrackerscreen.png"
            );
    }

    public void InviteFriends()
    {
        FB.AppRequest (
            message: "Give Crystal Cracker a try on iPhone or Android!  It's too fun!",
            title: "Invite your friends to play Crystal Cracker"
        );
    }

    //All Scores API related items

    public void QueryScores()
    {
        highScoresPanel.SetActive (true);
        FB.API ("app/scores?fields=score,user.limit(30)", Facebook.HttpMethod.GET, ScoresCallback);
    }

    public 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;
            ScorePanel.transform.localScale = new Vector2(1,1);

            Transform ThisScoreName = ScorePanel.transform.Find ("FriendName");
            Transform ThisScoreScore = ScorePanel.transform.Find ("FriendScore");
            Text ScoreName = ThisScoreName.GetComponent<Text>();
            Text ScoreScore = ThisScoreScore.GetComponent<Text>();

            ScoreName.text = user["name"].ToString();
            ScoreScore.text = entry["score"].ToString();

            Transform TheUserAvatar = ScorePanel.transform.Find("FriendAvatar");
            Image UserAvatar = TheUserAvatar.GetComponent<Image>();

            FB.API (Util.GetPictureURL(user["id"].ToString(), 128, 128), Facebook.HttpMethod.GET, delegate(FBResult pictureResult) {
                if (pictureResult.Error != null)
                {
                    Debug.Log (pictureResult.Error);
                }
                else
                {
                    UserAvatar.sprite = Sprite.Create (pictureResult.Texture, new Rect(0,0,128,128), new Vector2(0,0));
                }
            });

        }
    }

    public void SetScore()
    {
        if (FB.IsLoggedIn) {
            GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
            if (gameControllerObject != null) {
                gameController = gameControllerObject.GetComponent <GameController> ();
            }
            if (gameController == null) {
                Debug.Log ("Cannot find 'GameController' script");
            }

            var scoreData = new Dictionary<string,string> ();
            scoreData ["score"] = gameController.score.ToString ();
            FB.API ("/me/scores", Facebook.HttpMethod.POST, delegate(FBResult result) {
                Debug.Log ("Score Submit Result: " + result.Text);
            }, scoreData);
        }
   
    }
}
1 Like

bumping for visibility. I still haven’t figured this one out, though I’ve spent the week looking online for more information.

1 Like

What is the log message you are getting at this point?
Debug.Log ("Scores Callback: " + result.Text);

Also I would think you will have to add the user_friends permission to your Fb.Login to get friend list

had exactly the same issue, was fixed by all the players deleting the app and redoing their permissions. Now suddenly we call see eachothers scores.
Also we made the app live then back to development mode

Invite friends and share score dont do anything wqhen clicked, no dialog window appears, yet they work fine in unity

I have same problem, but deleting app and redoing permissions has not worked? when I login using the token for one of my 10 test users I can see all the other test users scores, but if I login using my actual fb account and then login with a friends fb account, we can only see our own scores, and not our own and each others, really frustrating! Anyone any ideas? My app is approved by fb and has the permissions required for the scores api…

today i am going to remove the facebook scoring entirely and go with a 3rd party scoring system.
They do not allow you to have a leader board of all people playing the game, only your frineds!

I know, thats why I implemented my own global leaderboard using the dreamlo asset. I am considering releasing my code as an asset which uses the Facebook SDK asset for the friends leaderboard, and the dreamlo asset for the global leaderboard.

I have the same problem i submitted mt application for publish_actions permissions and it got approved, but i don’t see my friends scores. When i use my test users, even before the app got approved, i can see their friends and scores and everything. Did you find a solution to the problem? Can anyone else help please?

Thank You

Just add to FB.Login “user_friends”. Example: FB.Login(“email,publish_actions,user_friends”, AuthCallback);

I also followed the same tutorial ! :stuck_out_tongue: I too have the same problem :confused: Any suggestions?

Hi. Same problem for me. If I use FB.LogInWithPublishPermissions (new List () { “publish_actions” }, LoginCallBack); all the users are able to save their score but can not see friends scores.
If I use FB.LogInWithPublishPermissions (new List () { “publish_actions” , “user_friends” }, LoginCallBack); the application crash on loggin. Same with FB.LogInWithPublishPermissions (new List () { “publish_actions, user_friends” }, LoginCallBack);
On the editor applications works but no friends are listed.
does someone has a solution?

I believe you have to get the user_friends through the
LogInWithReadPermissions

First. Then you do the publish permissions at another time (usually when you actually need it)

Thanks Brathnann. I have tried FB.LogInWithReadPermissions (new List () { “user_friends” }, LoginCallBack); and friends still do not appear. I also tryed lot of things with the API Graph explorer Log into Facebook and same result.
I will try to put back to development mode and publish again in facebook.

hmm…I don’t use the FB leaderboard system. We have one with Playfab and we can log into it using FB credentials and get a leaderboard that includes friends.

How are you testing friends? Are you using testing accounts where you made them friends and did a high score or you using other real people that are developers on the project and testing with them?

I’m testing with my son’s account.
So finally it works. It seems that once a user installs the applications and give some permission, those will never change, even if he uninstall and re install a new version of the applications asking for more permission.
You need to go to facebook and manually delete the game in the user configuration.
Thanks for your help!

@javier-mazzurco hello ,
what kind of login permission you have used , i have publish actions cleared from facebook , i used this to login
FB.LogInWithPublishPermissions(new List() { “publish_actions,email,public_profile,user_friends” }, LoginCallBack);
and still can’t see my real FB friends score
please help

I don’t believe publishpermissions lets you get the friends permission. You’ll need to use the LoginWithReadPermissions first. Then later you should ask for publish permissions if you need it.

okey thank you ,
can you please explain further what do you mean by later , do you mean when i want to overwrite a FB score for an example ,

Normally you only want to ask for publish permission when you need it. The first time you require it for example. Let’s say you require publish permission to post a score, you should check if your user already granted that permission and if not, do the LoginWithPublishPermission to prompt for that permission. If they already granted it, you should be able to skip that and just publish the score.

Facebook considers this best practice.

i see what you mean , i tried a quick solution but i’m getting a difference permissions issue which is not granting me publish actions and email even though i asked for it ,
here is the code , please have a look at it and tell me what you think about this

public void FBlogin()
    {
        if (!FB.IsLoggedIn) 

            FB.LogInWithReadPermissions(new List<string>() {"email","public_profile","user_friends" }, LoginCallBack);
  
}
//login call back
void LoginCallBack(IResult result)
    {
  
        FB.API("/me/permissions", HttpMethod.GET, delegate (IGraphResult response) {

            Debug.Log("response" + response.RawResult);

            var perm = Json.Deserialize(response.RawResult) as Dictionary<string, object>;

            var permList = new List<object>();
            permList = (List<object>)(perm["data"]);

                    foreach (object permissiom in permList)
                    {

                      var Permission = (Dictionary<string, object>)permissiom;

                      if (Permission["permission"].ToString() == "publish_actions")
                        {
                            Debug.Log("publish_actions  granted !!");
                        }
                    else
                        {
                            Debug.Log("publish_actions not granted !!");
                    FB.LogInWithPublishPermissions(new List<string>() { "publish_actions" });
                }
                    } 
        });
}

Debug.log permissions result
response{“data”:[{“permission”:“user_friends”,“status”:“granted”},{“permission”:“public_profile”,“status”:“granted”}]}