Firebaseauth - 未知错误代码

问题描述 投票:1回答:1

我正在使用Firebase AuthUI登录我的应用程序,特别是使用Facebook。我已在我的控制台中验证我的登录成功,因为我看到用户已添加。

但是,我的回调方法没有触发,我已经实现了toast,我不知道为什么没有调用success方法。我已记录错误代码,不知道它表示什么问题。我是否正确捕获错误?它生成-1,我在Firebase AuthUI docs中看不到:

public class LoginActivity extends AppCompatActivity {

private static final int RC_SIGN_IN = 123;
private static final String USERS = "Users";


private FirebaseAuth mAuth;


FirebaseDatabase mBaseRef;
DatabaseReference mUserRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mAuth = FirebaseAuth.getInstance();


    mBaseRef = FirebaseDatabase.getInstance();
    mUserRef = mBaseRef.getReference(USERS);


    startActivityForResult(AuthUI.getInstance()
            .createSignInIntentBuilder()
            .setAvailableProviders(Arrays.asList(
                    new AuthUI.IdpConfig.EmailBuilder().build(),
                    new AuthUI.IdpConfig.GoogleBuilder().build(),
                    new AuthUI.IdpConfig.FacebookBuilder().build()))
            .build(), RC_SIGN_IN);

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // RC_SIGN_IN is the request code you passed into startActivityForResult(...) when starting the sign in flow.
    if (requestCode == RC_SIGN_IN) {


        IdpResponse response = IdpResponse.fromResultIntent(data);

        Log.v("RESPONSE", String.valueOf(response.getErrorCode()));


        // Successfully signed in
        if (resultCode == RESULT_OK) {
            Toast.makeText(getApplicationContext(), "SIGNED IN SUCCESSFULLY", Toast.LENGTH_LONG).show();


            if (mAuth.getCurrentUser() != null) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("TEST USER ", mAuth.getCurrentUser());
                mUserRef.push().updateChildren(map);
                Intent i = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(i);
                finish();
            } else {
                //not signed in
                Toast.makeText(getApplicationContext(), "SIGN IN FAILED", Toast.LENGTH_LONG).show();
                return;
            }
        } else {
            // Sign in failed
            if (response == null) {
                // User pressed back button
                Toast.makeText(getApplicationContext(), "SIGN IN CANCELLED", Toast.LENGTH_LONG).show();
                return;
            }

            if (response.getErrorCode() == ErrorCodes.NO_NETWORK) {
                Toast.makeText(getApplicationContext(), "NO INTERNET CONNECTION", Toast.LENGTH_LONG).show();
                return;
            }

            if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) {
                Toast.makeText(getApplicationContext(), "UNKNOWN ERROR", Toast.LENGTH_LONG).show();
                return;
            }
         }

      }
    }

 }

编辑:我已经添加了完整的活动enter image description here

编辑:我的日志运行非常快,然后错误在我可以读取之前自动删除,它实际上可能是StackOverflow。

java android firebase firebase-authentication firebaseui
1个回答
2
投票

错误代码仅在通过检查onActivityResult结果代码实际发生错误时才有效,否则它只会返回-1(Activity.RESULT_OK),如您所注意到的那样。这是sample的一个例子:

private void handleSignInResponse(int resultCode, Intent data) {
    IdpResponse response = IdpResponse.fromResultIntent(data);

    // Successfully signed in
    if (resultCode == RESULT_OK) {
        startSignedInActivity(response);
        finish();
    } else {
        // Sign in failed
        if (response == null) {
            // User pressed back button
            showSnackbar(R.string.sign_in_cancelled);
            return;
        }

        if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) {
            showSnackbar(R.string.no_internet_connection);
            return;
        }

        showSnackbar(R.string.unknown_error);
        Log.e(TAG, "Sign-in error: ", response.getError());
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.