我正在尝试在游戏中实现排行榜。
我写了这段代码:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_FILE)
    .build();

mGoogleApiClient.connect();
//....

while(!mGoogleApiClient.isConnected())Log.d("","NO CONNECTED");
Games.Leaderboards.submitScore(mGoogleApiClient, "MY_LEADERBOARD_ID",newscore);


为什么mGoogleApiClient.isConnected()返回始终为false?

EDIT1:好的,现在可以了(我已将Drive.API更改为Games.API,将Drive.SCOPE_FILE更改为Games.SCOPE_GAME),但是当我调用submitScore()时,即使在日志中都可以,排行榜也仍然是空的。如何检查submitScore()是否真的有效?

EDIT2:我曾经

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, "MY_LEADERBOARD_ID"), REQ_LEADERBOARD);


一切正常!

最佳答案

您需要向Builder(或GoogleApiClient)添加几个回调侦听器。最有可能发生的情况是登录失败,因为您还没有权限。您需要处理该失败,以便用户可以授权您的应用程序。

更多阅读:http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/

10-06 03:25