Firebaseと統合されたFacebookログイン用のアクティビティを1つ作成しています。Firebaseは認証リストのFacebookユーザーを保存していません
私はFirebaseでFacebookのログインを有効にし、すべてのfirebaseの手順とFacebook Developer ConsoleのすべてのFacebookの手順に従っています。
私のアクティビティにはcom.facebook.widget.LoginButtonがあり、このボタンをクリックするとFacebookのログインページが表示され、認証情報の入力、アプリの自動化とログインが可能になりました。
しかし、私が再びアプリケーションに入ると、ログインボタンが表示され、Facebookのログインは保存されません(キャッシュされます)。
Firebase認証ユーザーリストも保存されていません。
何が間違っている可能性がありますか。
以下のマイコード。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_login);
mFirebaseUtils = new FirebaseUtils();
mFirebaseUtils.setFirebase();
try {
@SuppressWarnings("rawtypes")
Class strictModeClass = Class.forName("android.os.StrictMode");
Class strictModeThreadPolicyClass = Class
.forName("android.os.StrictMode$ThreadPolicy");
Object laxPolicy = strictModeThreadPolicyClass.getField("LAX").get(
null);
@SuppressWarnings("unchecked")
Method method_setThreadPolicy = strictModeClass.getMethod(
"setThreadPolicy", strictModeThreadPolicyClass);
method_setThreadPolicy.invoke(null, laxPolicy);
} catch (Exception e) {
}
// View Pager
initData();
mAuth = mFirebaseUtils.mAuth;
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());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.btnLoginFacebook);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
}
@Override
public void onError (FacebookException error){
Log.d(TAG, "facebook:onError", error);
}
});
}
private void handleFacebookAccessToken(AccessToken token) {
Log.d(TAG, "handleFacebookAccessToken:" + token);
// [START_EXCLUDE silent]
//showProgressDialog();
// [END_EXCLUDE]
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// [START_EXCLUDE]
//hideProgressDialog();
// [END_EXCLUDE]
}
});
}
public void signOut() {
mAuth.signOut();
LoginManager.getInstance().logOut();
}
public String getAndroidVersion() {
String release = Build.VERSION.RELEASE;
int sdkVersion = Build.VERSION.SDK_INT;
return "Android SDK: " + sdkVersion + " (" + release +")";
}
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
FirebaseUser user = mAuth.getCurrentUser();
}
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
//case R.id.button_facebook_signout:
// signOut();
// break;
}
}