- Home /
Facebook SDK - “FB.API” not saving or loading scores
I'm creating a game for the Facebook Canvas using the official Facebook SDK. Despite using code directly from the Facebook Unity example, I cannot save nor load a score value. I receive no error or message whatsoever - A value of 0 is always returned when I attempt to retrieve the score. Everything else (logging in, posting to the news feed, etc.) is working fine - just not the score management. Also, this occurs both in the Unity editor and on the Facebook canvas itself.
I save the player's score like this:
public void SaveScore(int _score)
{
_fbScore = _score;
var _query = new Dictionary<string, string>();
_query["score"] = _fbScore.ToString();
FB.API("/me/scores", Facebook.HttpMethod.POST, delegate(FBResult r) { Util.Log("Result: " + r.Text); }, _query);
//FB.API ("/me/scores", Facebook.HttpMethod.POST, ScoreSaveCallBack, scoreData);
_hiScoreText.text = _fbScore.ToString();
}
I then try to retrieve the score with this method:
public void GetHighScore()
{
if (_fbIsInited)
FB.API ("/app/scores?fields=score,user.limit(20)", Facebook.HttpMethod.GET, GetScoreCallBack);
}
Callback method:
void GetScoreCallBack(FBResult _result)
{
try
{
List<object> _scoresList = Util.DeserializeScores(_result.Text);
foreach(object _score in _scoresList)
{
var _entry = (Dictionary<string,object>) _score;
var _user = (Dictionary<string,object>) _entry["user"];
string _userId = (string)_user["id"];
if (string.Equals(_userId, FB.UserId))
{
_fbScore = GetScoreFromEntry(_entry);
_hiScoreText.text = _fbScore.ToString();
Debug.Log("FB SCORE: + " + _fbScore);
}
}
}
catch (System.Exception _e)
{
Debug.Log(_e.Message);
}
}
As the score returned is always 0, I do not know whether the problem is with the save or load methods.
EDIT: To make matters worse, out of nowhere, I've started getting these errors when I attempt to post the score:
You are trying to load data from a www stream which had the following error when downloading.
403 Forbidden
UnityEngine.WWW:get_text()
FBResult:get_Text()
FacebookManager:<SaveScore>m__0(FBResult) (at Assets/Scripts/Facebook/FacebookManager.cs:138)
Facebook.<Start>c__Iterator0:MoveNext()
I haven't made any changes to the code, they just started appearing every time!
I have exactly the same problem, help would be appreciated please. The problem seems to be about permissions allowed by the app or user (your account). As 403 forbidden tell us that the server receive the request but dont have permission to send us the requested ressource (the /me/scores node).
I have the samo problem too. But strangely i can load the profil picture and draw it.
When I build for iOS and tried again in the editor all was fine.
hey guys.. you got some solution?? i am also stuck at this point.. please helpp me if you got any solution..
I'm also at this point trying to send my score from my app. I've tried with Friend Smash, the example game from FB (apps.facebook.com/friendsmashsample/). Score stays on zero... When I use graph api requesting /me/scores/ nothing appears except "data"...
Your answer
![](https://koobas.hobune.stream/wayback/20220613142801im_/https://answers.unity.com/themes/thub/images/avi.jpg)