Android排行榜不会显示

时间:2015-11-07 22:33:52

标签: android google-api leaderboard

使用以下方式提交分数时,我没有任何错误:

public void submitScore(int score)
{
    Games.Leaderboards.submitScore(mGoogleApiClient, "leaderboard_easy_leaderboard", score);
}

但是当我运行我的显示排行榜代码时:

public void displayScores()
{
    startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, "leaderboard_easy_leaderboard"), 0);
}

我收到以下错误:

11-07 17:00:39.873 32580-1830/? E/Volley: [161] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/games/v1/leaderboards/leaderboard_easy_leaderboard?language=en_US

11-07 17:00:39.882 32580-9774/? E/LeaderboardAgent: Unable to retrieve leaderboard leaderboard_easy_leaderboard

11-07 17:00:39.882 32580-9774/? E/LeaderboardAgent: No instance found for leaderboard leaderboard_easy_leaderboard for SOCIAL and ALL_TIME

googleapis链接显示以下文字:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

1 个答案:

答案 0 :(得分:1)

我需要做的就是:

getString(R.string.leaderboard_easy_leaderboard)

而不是:

"leaderboard_easy_leaderboard"

所以最终的解决方案是:

public void displayScores()
{
    startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, getString(R.string.leaderboard_easy_leaderboard)), 0);
}