gpt4 book ai didi

java - Firebase AuthUI - 未知错误代码

转载 作者:行者123 更新时间:2023-11-29 19:01:22 24 4
gpt4 key购买 nike

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

但是,我的回调方法没有触发,我已经实现了 toasts,但我不知道为什么没有调用成功方法。我已经记录了错误代码,但不知道它表示什么问题。我是否正确捕获了错误?它正在生成 -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;
}
}

}
}

}

编辑:我添加了完整的 Activity enter image description here

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

最佳答案

错误代码仅在通过检查 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());
}
}

关于java - Firebase AuthUI - 未知错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49000718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com