【发布时间】:2017-07-11 02:55:38
【问题描述】:
我使用 firebase 进行了登录活动以连接谷歌。用户可以毫无问题地登录现在我想在另一个活动中显示排行榜但是,当我检查用户是否已登录并尝试显示排行榜时出现错误:
E/UncaughtException: java.lang.IllegalStateException: GoogleApiClient 必须连接。
如何使用 Firebase 连接 GoogleApiClient?我尝试过使用mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);,但这也不起作用。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_achievements);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// connection failed, should be handled
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
////// is crashing googleapiclient not connected
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
getString(R.string.leaderboard_la_classifica)), REQUEST_LEADERBOARD);
} else {
// User is signed out
}
// ...
}
};
}
【问题讨论】:
标签: java android firebase google-play-games