Search Unity

Facebook SDK - “FB.API” not saving or loading score values

Discussion in 'Scripting' started by drjamiearron, Apr 15, 2014.

  1. drjamiearron

    drjamiearron

    Joined:
    Jun 8, 2012
    Posts:
    134
    Based on the code provided by the official Facebook Unity project, 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.

    I save the player's score like this:

    Code (csharp):
    1. public void SaveScore(int _score)
    2. {
    3.     _fbScore = _score;
    4.  
    5.     var _query = new Dictionary<string, string>();
    6.     _query["score"] = _fbScore.ToString();
    7.  
    8.     FB.API("/me/scores", Facebook.HttpMethod.POST, delegate(FBResult r) { Util.Log("Result: " + r.Text); }, _query);
    9.  
    10.     //FB.API ("/me/scores", Facebook.HttpMethod.POST, ScoreSaveCallBack, scoreData);
    11.     _hiScoreText.text = _fbScore.ToString();
    12. }
    I then try to retrieve the score with this method:
    Code (csharp):
    1.  
    2. public void GetHighScore()
    3. {
    4.     if (_fbIsInited)
    5.         FB.API ("/app/scores?fields=score,user.limit(20)", Facebook.HttpMethod.GET, GetScoreCallBack);
    6. }
    Callback method:

    Code (csharp):
    1. void GetScoreCallBack(FBResult _result)
    2. {
    3.     try
    4.     {
    5.         List<object> _scoresList = Util.DeserializeScores(_result.Text);
    6.         foreach(object _score in _scoresList)
    7.         {
    8.             var _entry = (Dictionary<string,object>) _score;
    9.             var _user  = (Dictionary<string,object>) _entry["user"];
    10.  
    11.             string _userId = (string)_user["id"];
    12.  
    13.             if (string.Equals(_userId, FB.UserId))
    14.             {
    15.                 _fbScore = GetScoreFromEntry(_entry);
    16.                 _hiScoreText.text = _fbScore.ToString();
    17.                 Debug.Log("FB SCORE: + " + _fbScore);
    18.             }
    19.         }
    20.     }
    21.     catch (System.Exception _e)
    22.     {
    23.         Debug.Log(_e.Message);
    24.     }
    25. }
    As the score returned is always 0, I do not know whether the problem is with the save or load methods. Can anyone help?
     
  2. drjamiearron

    drjamiearron

    Joined:
    Jun 8, 2012
    Posts:
    134
    To make matters worse, out of nowhere, I've started getting these errors when I attempt to post the score:

    Code (csharp):
    1.  
    2. You are trying to load data from a www stream which had the following error when downloading.
    3. 403 Forbidden
    4. UnityEngine.WWW:get_text()
    5. FBResult:get_Text()
    6. FacebookManager:<SaveScore>m__0(FBResult) (at Assets/Scripts/Facebook/FacebookManager.cs:138)
    7. Facebook.<Start>c__Iterator0:MoveNext()
    8.  
    I haven't made any changes to the code, they just started appearing every time!
     
  3. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    Hi there, any news on this?
     
  4. Ekta-Mehta-D

    Ekta-Mehta-D

    Joined:
    Feb 25, 2013
    Posts:
    24
    hey guys.. did you find any solution for this???
     
  5. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    No.
     
  6. zaraku

    zaraku

    Joined:
    Oct 7, 2013
    Posts:
    2
    hey,did you check out your app details on fb developers ,category not select games?
     
  7. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    Zaraku, I checked and the category is Game, subcategory Simulation.
     
  8. zaraku

    zaraku

    Joined:
    Oct 7, 2013
    Posts:
    2
    oh...still not save score?

    Did you login request "publish_actions"?

    -->FB.Login("publish_actions", LoginCallback);
     
  9. AlbertJNT

    AlbertJNT

    Joined:
    Aug 7, 2014
    Posts:
    5
    Anybody have this solution ?
     
  10. huunam09

    huunam09

    Joined:
    Aug 15, 2013
    Posts:
    1
    Hi all,
    I think its work.
    Data :
    Code (CSharp):
    1. void GetScoreCallBack(FBResult _result)
    2.     {
    3.         try
    4.         {
    5.             Debug.Log(_result.Text);
    6.             Dictionary<string, object> playerScore = Json.Deserialize(_result.Text) as Dictionary<string, object>;
    7.             object score;
    8.             var listObject = new List<object>();
    9.             if (playerScore.TryGetValue("data", out score))
    10.             {
    11.                 listObject = (List<object>)score;
    12.                 var temp1 = ((Dictionary<string,object>)listObject[0]);
    13.                 Debug.Log(temp1["score"]);
    14.             }
    15.         }
    16.         catch (System.Exception _e)
    17.         {
    18.             Debug.Log(_e.Message);
    19.         }
    20.     }
    I will get score : 12312
     
  11. Ekta-Mehta-D

    Ekta-Mehta-D

    Joined:
    Feb 25, 2013
    Posts:
    24
  12. sumitKg

    sumitKg

    Joined:
    Dec 3, 2014
    Posts:
    1
    didu find the solution for this --- anyone ???
     
  13. DuKE1921

    DuKE1921

    Joined:
    Dec 23, 2014
    Posts:
    1
    Yeah, i guess i found the solution.
    While creating a test user for your game in facebook(roles->test users), make sure to tick yes for
    "Authorize Test Users for This App?" and write "publish_actions" in login permissions. Then create this test user and login with it. And your problem should be solved. (This is what worked for me.)
     
  14. FlyerBird

    FlyerBird

    Joined:
    May 13, 2017
    Posts:
    1
    i need help for save fb all friend scores and show to everyone like subway surfer game.....