我已經使用Firebase與Google進行了登錄活動。用戶可以毫無問題登錄現在我想不過來顯示在另一個活動排行榜,當我檢查,如果用戶登錄,我儘量表現排行榜我得到的錯誤:Android FireBase - 連接到遊戲服務排行榜
E/UncaughtException: java.lang.IllegalStateException: GoogleApiClient must be connected.
我如何連接GoogleApiClient
使用firebase?我曾嘗試使用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
}
// ...
}
};
}