我正在嘗試使用Firebox實施2供應商(Facebook & Google)登錄活動。我測試過該系統,在以下情況下,退出由單一按鈕調用下面的定義signOut()
方法來完成:通過Facebook登錄後無法通過Facebook登錄
- 登錄W/Facebook的,註銷,再次登錄W/Facebook的。
- 通過Facebook登錄,註銷,使用Google登錄。
- 登錄w/Google,註銷,再次登錄w/Google。
- 登錄w/Google,註銷,再次登錄w/Facebook。
場景1-3是成功的,但是當我試圖與谷歌登錄,註銷,然後與Facebook登錄,我得到的OnCompleteListener
在handleFacebookAccessToken
方法onComplete
方法ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL
錯誤。奇怪的是,這隻發生在與Google簽約之後,我懷疑我沒有正確實施Google的註銷機制。
我的主要胡亞蓉如下所示,未指定佈局文件,因爲它是很長,但是查看的名字是自explanitory:
public class MyActivity extends AppCompatActivity implements SKPrepareMapTextureListener, UpdateDbTask.UpdateDbTaskListener, GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {
private GoogleApiClient mGoogleApiClient;
private static final int RC_SIGN_IN = 0;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private CallbackManager mCallbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
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(Constants.APP_NAME, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(Constants.APP_NAME, "onAuthStateChanged:signed_out");
}
}
};
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(Constants.defaultWebClientId)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_sign_in_button);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(Constants.APP_NAME, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(Constants.APP_NAME, "facebook:onCancel");
}
@Override
public void onError(FacebookException error) {
Log.d(Constants.APP_NAME, "facebook:onError", error);
}
});
}
private void handleFacebookAccessToken(AccessToken token) {
Log.d(Constants.APP_NAME, "handleFacebookAccessToken:" + token);
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(Constants.APP_NAME, "signInWithCredential:onComplete:" + task.isSuccessful());
if (!task.isSuccessful()) {
Log.w(Constants.APP_NAME, "signInWithCredential", task.getException());
Toast.makeText(MyActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
} else
Toast.makeText(MyActivity.this, "Logged in with facebook.",
Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
public void signOut() {
// Firebase sign out
mAuth.signOut();
// Google sign out
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Toast.makeText(MyActivity.this, "signed out from google " + status.getStatusMessage(),
Toast.LENGTH_LONG).show();
}
});
LoginManager.getInstance().logOut();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.google_sign_in_button:
signIn();
break;
}
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
} else {
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
}
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
firebaseAuthWithGoogle(acct);
} else {
}
}
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct) {
Log.d(Constants.APP_NAME, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(Constants.APP_NAME, "signInWithCredential:onComplete:"
+ task.isSuccessful());
if (!task.isSuccessful()) {
Log.w(Constants.APP_NAME, "signInWithCredential", task.getException());
Toast.makeText(MyActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MyActivity.this, "Logged in with google",
Toast.LENGTH_SHORT).show();
}
}
});
}
登錄附:
10-05 16:09:23.243 4454-4454/? E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
10-05 16:09:23.403 29999-30148/? E/Drive.UninstallOperation: Package still installed com.android.vagabond
10-05 16:09:24.020 31516-31516/? E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.flags.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.asus.filemanager-2/base.apk"],nativeLibraryDirectories=[/data/app/com.asus.filemanager-2/lib/arm64, /system/lib64, /vendor/lib64]]
10-05 16:09:24.027 31516-31516/? E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.asus.filemanager-2/base.apk"],nativeLibraryDirectories=[/data/app/com.asus.filemanager-2/lib/arm64, /system/lib64, /vendor/lib64]]
10-05 16:09:24.388 29999-31493/? E/IntentOperationSvc: Failed to instantiate Chimera operation impl, dropping operation
10-05 16:09:24.516 10694-10694/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(836): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
10-05 16:09:24.937 4454-4454/? E/NetworkScheduler.SR: Invalid parameter app
10-05 16:09:24.937 4454-4454/? E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
10-05 16:09:27.092 31501-31501/com.android.vagabond E/DB created: false
10-05 16:09:30.179 31501-31501/com.android.vagabond E/DB Hash request error: Cannot connect to Internet...
10-05 16:09:39.153 31643-31643/? E/DynamiteModule: Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.android.gms.crash.ModuleDescriptor" on path: DexPathList[[zip file "/data/app/com.asus.filemanager-2/base.apk"],nativeLibraryDirectories=[/data/app/com.asus.filemanager-2/lib/arm64, /system/lib64, /vendor/lib64]]
10-05 16:09:57.964 4454-4454/? E/ChimeraSrvcProxy: Can't find Chimera service impl class com.google.android.gms.clearcut.service.VacuumChimeraService
10-05 16:09:57.964 4454-4454/? E/ChimeraSrvcProxy: Proxy without impl dropping onStart()
10-05 16:09:59.822 29725-29733/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: [email protected])
10-05 16:10:11.388 29725-29733/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: [email protected])
10-05 16:10:32.541 31501-31831/com.android.vagabond E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
10-05 16:05:19.890 28275-28275/? D/com.facebook.appevents.AppEventsLogger: To set source application the context of activateApp must be an instance of Activity
10-05 16:10:31.929 861-13544/? I/ActivityManager: START u0 {act=NATIVE_WITH_FALLBACK cmp=com.android.vagabond/com.facebook.FacebookActivity (has extras)} from uid 10114 on display 0
10-05 16:10:32.612 861-881/? I/ActivityManager: Displayed com.android.vagabond/com.facebook.FacebookActivity: +670ms
10-05 16:10:36.075 861-881/? I/WindowManager: Destroying surface Surface(name=com.android.vagabond/com.facebook.FacebookActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
10-05 16:10:43.266 861-881/? I/WindowManager: Destroying surface Surface(name=com.android.vagabond/com.facebook.FacebookActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
10-05 16:10:44.229 861-4529/? I/WindowManager: Destroying surface Surface(name=com.android.vagabond/com.facebook.FacebookActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
10-05 16:10:44.251 861-26457/? I/WindowManager: Destroying surface Surface(name=com.android.vagabond/com.facebook.FacebookActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
10-05 16:10:44.312 31501-31501/com.android.vagabond D/Vagabond: facebook:onSuccess:[email protected]
10-05 16:10:44.312 31501-31501/com.android.vagabond D/Vagabond: handleFacebookAccessToken:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, contact_email, email]}
10-05 16:10:54.311 861-26455/? I/WindowManager: Destroying surface Surface(name=com.android.vagabond/com.facebook.FacebookActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
你有任何消息或日誌? –
@JoséCarlos當然,對不起,我添加了日誌。另外,我沒有「com.facebook.FacebookActivity」活動,這是否有任何相關性? –