关于Android Studio上的谷歌游戏服务
我正在尝试在我的项目中添加排行榜和电子版系统,大约3天 我可以登录到我的应用程序,但当我尝试打开排行榜时,它会说:关于Android Studio上的谷歌游戏服务,android,android-studio,google-api,google-play-games,google-api-client,Android,Android Studio,Google Api,Google Play Games,Google Api Client,我正在尝试在我的项目中添加排行榜和电子版系统,大约3天 我可以登录到我的应用程序,但当我尝试打开排行榜时,它会说: E/UncaughtException: java.lang.IllegalStateException: GoogleApiClient is not configured to use the Games Api. Pass Games.API into GoogleApiClient.Builder#addApi() to use this feature.
E/UncaughtException: java.lang.IllegalStateException: GoogleApiClient is not configured to use the Games Api. Pass Games.API into GoogleApiClient.Builder#addApi() to use this feature.
at com.google.android.gms.common.internal.zzac.zza(Unknown Source)
at com.google.android.gms.games.Games.zzc(Unknown Source)
at com.google.android.gms.games.Games.zzb(Unknown Source)
at com.google.android.gms.games.Games.zzi(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at com.google.android.gms.games.internal.api.LeaderboardsImpl.getLeaderboardIntent(Unknown Source)
at tr.com.blogspot.etkinlikhavuzu.benimilkogretmenim.Ilksayfa.onClick(Ilksayfa.java:309)
at android.view.View.performClick(View.java:5702)
at android.widget.TextView.performClick(TextView.java:10888)
at android.view.View$PerformClick.run(View.java:22541)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
我怎样才能解决这个问题
我写了这段代码:
case R.id.Enbasarili:
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
getResources().getString(R.string.leaderboard_en_cok_70_ve_ustu_basari_gosterenler)), RC_UNUSED);
break;
感谢您的帮助……尝试检查这些文档,然后 获取Google Api客户端并连接 为了对Google Play games服务进行任何API调用,您的游戏必须具有对该对象的引用。使用GoogleAppClient.Builder类在中创建对象。例如: 为了让您的游戏与Google Play games服务进行通信,您的客户端必须首先建立连接。一旦游戏不再需要访问这些服务,您可以断开客户端的连接 编辑: 为了使用Google Play games服务,您的游戏需要实现用户登录,以使用Google Play games服务验证玩家的身份。如果用户未通过身份验证,您的游戏在调用Google Play games服务API时将遇到错误 请参阅,以更好地了解GooglePlay游戏的代码实现
希望这有帮助。好吧,
GoogleAppClient没有配置为使用游戏Api。
您是否将Games.Api传递到GoogleAppClient.Builder中#addApi()以使用此功能
?我想我没有。我不知道该怎么做。也许你应该去读一些文档,比如。我真的,我在网上搜索了一天,只为了这个,但搜索错误的地方。无论如何,谢谢你。我想我明白了。谢谢你的评论。但是当我昨天添加这个代码时,它说:onConnectionFailed:ConnectionResult{statusCode=SIGN_IN_REQUIRED,resolution=pendingent{f1c8656:android.os。BinderProxy@3392f9b},message=null}我在创建时使用了以下内容:mGoogleApiClient=new-GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Games.API).addScope(Games.SCOPE\u Games.build();mGoogleApiClient.connect()代码>是的,您的游戏需要实现用户登录,以通过Google Play games服务验证玩家的身份。否则,在调用Google Play games服务API时将遇到错误。
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the Google Api Client with access to the Play Games services
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
// ...
}
private static int RC_SIGN_IN = 9001;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;
// ...
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (mResolvingConnectionFailure) {
// Already resolving
return;
}
// If the sign in button was clicked or if auto sign-in is enabled,
// launch the sign-in flow
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
// Attempt to resolve the connection failure using BaseGameUtils.
// The R.string.signin_other_error value should reference a generic
// error string in your strings.xml file, such as "There was
// an issue with sign in, please try again later."
if (!BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
// Put code here to display the sign-in button
}