- Home /
facebook leaderboard
Hi everyone, I have written this facebook script in which I Query scores of my game and set scores. Now in the editor with the test users everything works fine. I requested the publish_actions permissions and now I have it. But when I play my game, the only score I see is mine. In my friend's phone There is my score and his score. Here's my code:
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic;
public class FBholder : MonoBehaviour {
public static FBholder FBHolder;
public GameObject FBUIIsLoggedIn;
public GameObject FBUINotLoggedIn;
public GameObject FBUIUserName;
public GameObject FBUIUserImage;
private Dictionary <string,string> profile=null;
private List<object> ScoresList=null;
public GameObject ScoreEntryPanel;
public GameObject ScoreScrollList;
private bool StopCallingListener2;
public Button ShareWithFriendsButton;
public Button InviteFriendsButton;
public float HighScoreInFloat;
public Button LoginButton;
public bool StopCallingListener7;
void Awake () { if (FBHolder == null) { DontDestroyOnLoad (gameObject); FBHolder = this; } else if (FBHolder != this) Destroy (gameObject);
FB.Init (SetInit, OnHideUnity);
}
void Update()
{
if (Application.loadedLevelName == "Menù2" && StopCallingListener7 ) {
if(FB.IsLoggedIn==false){
LoginButton = GameObject.Find ("FBLoginButton").GetComponent<Button> ();
LoginButton.onClick.AddListener (() => FBLogin ());
}
FBUINotLoggedIn=GameObject.Find ("FBNotLoggedIn");
FBUIIsLoggedIn = GameObject.Find ("FBLoggedIn");
StopCallingListener7=false;
}
if (Application.loadedLevelName == "Menù2" && StopCallingListener2 && FB.IsLoggedIn) {
FBUIIsLoggedIn = GameObject.Find ("FBLoggedIn");
FBUIUserImage=GameObject.Find ("FBUserImage");
FBUIUserName=GameObject.Find ("UserName");
ScoreScrollList=GameObject.Find ("ScrollContain");
ShareWithFriendsButton = GameObject.Find ("FBShareButton").GetComponent<Button> ();
InviteFriendsButton = GameObject.Find ("FBInviteButton").GetComponent<Button> ();
ShareWithFriendsButton.onClick.AddListener(() => ShareWithFriends());
InviteFriendsButton.onClick.AddListener(() => InviteFriends());
StopCallingListener2=false;
}
if (Application.loadedLevelName != "Menù2") {
StopCallingListener2 = true;
StopCallingListener7=true;
}
}
private void SetInit()
{
Debug.Log ("FB Init Done.");
if (FB.IsLoggedIn)
{
Debug.Log ("FB Logged In");
DealWithFbMenùs(true);
}
else
{
DealWithFbMenùs(false);
}
}
private void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
Time.timeScale = 0;
else
{
Time.timeScale=1;
}
}
public void FBLogin()
{
LoginButton = GameObject.Find ("FBLoginButton").GetComponent<Button> ();
LoginButton.onClick.AddListener(() => FBLogin());
FB.Login ("email,user_friends,publish_actions", AuthCallBack);
}
void AuthCallBack (FBResult result)
{
if (FB.IsLoggedIn)
{
Debug.Log("FB Login worked!");
DealWithFbMenùs(true);
}
else
{
Debug.Log("FB login Fail!");
DealWithFbMenùs(false);
}
}
void DealWithFbMenùs (bool IsLoggedIn)
{
if (IsLoggedIn)
{
FBUIIsLoggedIn.SetActive(true);
FBUINotLoggedIn.SetActive(false);
//Get profile picture
FB.API(Util.GetPictureURL("me",128,128),Facebook.HttpMethod.GET,DealWithProfilePicture);
//Get Username
FB.API("/me?fields=id,first_name",Facebook.HttpMethod.GET,DealWithUserName);
//Update LeaderBoard and Show it
QueryScores();
}
else
{
FBUIIsLoggedIn.SetActive(false);
FBUINotLoggedIn.SetActive(true);
}
}
void DealWithProfilePicture(FBResult result)
{
if (result.Error != null)
{
Debug.Log("Problem getting Profile Picture");
FB.API(Util.GetPictureURL("me",128,128),Facebook.HttpMethod.GET,DealWithProfilePicture);
return;
}
Image UserAvatar = FBUIUserImage.GetComponent<Image>();
UserAvatar.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 (0, 0));
}
void DealWithUserName(FBResult result)
{
if (result.Error != null)
{
Debug.Log("Problem getting UserName");
FB.API("/me?fields=id,first_name",Facebook.HttpMethod.GET,DealWithUserName);
return;
}
profile = Util.DeserializeJSONProfile (result.Text);
Text UserNameMSG = FBUIUserName.GetComponent<Text>();
UserNameMSG.text="Hello, "+profile["first_name"];
} public void LogOutFromFB() { FB.Logout();
}
public void ShareWithFriends ()
{
FB.Feed (linkCaption: "This Game literally Blow Your Mind!",
link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest"),
linkName: "How much can you resist?",picture:"http://sesyprojects.com/1737015_orig.png");
}
public void InviteFriends()
{
FB.AppRequest (message:"How much can you resist?",title:"Challenge your friends on HypnoTrip Game!");
}
public void SetScore()
{
var ScoreData = new Dictionary<string,string> ();
ScoreData ["score"] = GameSaver.gameSaver.HighScoreINT.ToString();
FB.API ("/me/scores", Facebook.HttpMethod.POST, delegate(FBResult result) {
Debug.Log ("Score submit result: " + result.Text);
}, ScoreData);
}
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 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();
HighScoreInFloat= int.Parse(entry["score"].ToString())/1000.0f;
int minutesTimer = Mathf.FloorToInt (HighScoreInFloat / 60F);
int secondsTimer = Mathf.FloorToInt (HighScoreInFloat - minutesTimer * 60);
ScoreScore.text = string.Format ("{0:00}:{1:00}", minutesTimer, secondsTimer);
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));
}
});
}
}
} Am I missing something? Thank You
In some forum I read about deleting the app from facebook developers and reinstall every app on every device... Any of you have ever had this problem? I used the greyzoned tutorial
When you friend granted 'publish_actions', what privacy setting did they select? If they selected a privacy group that does not include you, ie: 'Only $$anonymous$$e', you are not able to see the scores the publish via the Scores API.
Well it could be. Is there a way to know which privacy setting did the select?
@Stefano9528 I recommend using platform test users: https://developers.facebook.com/docs/apps/test-users
Is the app still in sandbox mode, i.e. not public and available to all users?
If not the only people that will show up in the friends list are test users or accounts that are on the list of Ad$$anonymous$$istrators, developers and testers.
No the app is live and available for the public. Probably is the privacy setticg that they selected the problem. I will make sure they won't select "only me".
Your answer
Follow this Question
Related Questions
how to vew other island on facebook game ?,hw to access other island on facebook game unity3d? 1 Answer
why can't i use unity web player even i downloaded it on facebook for a game 1 Answer
Cannot build for android with facebook sdk -- Unity 5.4.0f3 1 Answer
How to get a public profile permission facebook sdk 0 Answers