【问题标题】:Firebase Facebook authentication showing weird activityFirebase Facebook 身份验证显示奇怪的活动
【发布时间】:2016-10-11 22:14:08
【问题描述】:

我们正在为我们的一个项目实施 Firebase Facebook 身份验证。我们也遵循了文档中提到的步骤。

这是 oAuth 网址:

https://<APP_NAME>.firebaseapp.com/__/auth/handler

我还添加了其余的凭据(即APP_IDAPP_SECRET),此外,该应用处于开发阶段,我还添加了key hash 以及 Facebook 门户和 Firebase门户。

Login 初始流程运行良好,但是当用户 confirm 授予访问权限时,callback 寄存器根本没有响应,negativepositive 确认都没有。

这是我们的一段代码:

     private static final String TAG = "FacebookLogin";

    private CallbackManager mCallbackManager;

    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;

 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());
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                }
                // ...
            }
        };

        // Initialize Facebook Login button
        mCallbackManager = CallbackManager.Factory.create();
        LoginButton loginButton = (LoginButton) findViewById(R.id.button_facebook_login);
        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);
                // ...
            }
        });

@Override
    public void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }

    private void handleFacebookAccessToken(AccessToken token) {
        Log.d(TAG, "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(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(FacebookLoginActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }

                        // ...
                    }
                });
    }

如果我们遗漏了什么,请告诉我们。我假设callback URL 有问题,因此更多关于相同的信息会有所帮助,因为 Firebase 文档没有明确说明如何构建该 URL。提前致谢。

【问题讨论】:

    标签: android firebase firebase-authentication facebook-authentication


    【解决方案1】:

    你添加了吗

    mCallbackManager.onActivityResult(requestCode, resultCode, data);

    在您的 onActivityResult 块中?

    编辑

    参考来自 Firebase https://github.com/firebase/quickstart-android/blob/master/auth/app/src/minSdkJellybean/java/com/google/firebase/quickstart/auth/FacebookLoginActivity.java 的示例,

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
    }
    

    如果不添加,则不会有回调。

    【讨论】:

    • 我们没有,你能简单介绍一下吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2017-01-25
    • 1970-01-01
    相关资源
    最近更新 更多