Android:使用Firebase进行Facebook身份验证无法启动

问题描述 投票:0回答:2

我是Firebase和Facebook登录的新手,所以我在实时数据库上关注如何使用Facebook登录的许多教程。问题是,当您单击LoginButton时,似乎启动了一个活动,但之后它立即关闭。我已经实现了谷歌登录,一切正常,我真的找不到问题。

这是我如何做到的

mCallbackManager = CallbackManager.Factory.create();
    facebookButton.setReadPermissions("email", "public_profile");
    facebookButton.setFragment(this);
    LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG,"XD1");
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "cancel");
        }

        @Override
        public void onError(FacebookException error) {
            Log.e(TAG, "error connecting to fb", error);
        }
    });

private void handleFacebookAccessToken(AccessToken token){
    Log.d(TAG, "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile"));
                        getFragmentManager().beginTransaction().replace(R.id.frameLayout, PhoneFragment.newInstance(mAuth.getCurrentUser().getUid())).commit();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w("errore", "signInWithCredential:failure", task.getException());
                        Toast.makeText(getContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==REQUEST_GOOGLE) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "onResult di google");
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try{
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e){
            Log.e("errore", "errore, avvisare l'utente");
        }
    } else {
        Log.d(TAG, "onActivityResult di facebook richiamato");
        // Pass the activity result back to the Facebook SDK
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
    }
}

logcat显示的错误是SERVER_ERROR:[code] 1675030 [message]:执行查询时出错。 [extra]:执行操作“ProxyAuthAppLoginStartQuery”时出错:在Query.proxy_auth_app_login_start:字段实现引发异常。检查服务器日志以获取更多信息。

我认为这是因为测试用户,但添加它们没有任何改变

android firebase firebase-authentication facebook-login
2个回答
-1
投票

按照Facebook的教程将sdk添加到您的应用程序。很可能你的sdk没有正确设置所以当你启动Facebook身份验证时,由于客户端ID丢失,sdk失败了。此外,您必须在firebase项目控制台中设置Facebook,以便Firebase可以完成身份验证并获取必要的信息


-1
投票

问题是清单中的标签元数据。我无法在应用程序中添加元数据,因为CacheMeOutside在这里回答SERVER_ERROR: [code] 1675030 [message]: Error performing query,因为该标签已经在合并清单中(我认为是因为Firebase),所以我所要做的就是在我的字符串资源文件中更改字符串名称“facebook_app_id “to”facebook_application_id“这一切都很好。希望这可以帮助某人

© www.soinside.com 2019 - 2024. All rights reserved.