据我所知,所有Facebook和Firebase连接都是链接的,所有代码都应该正常运行。但是,即使从Facebook登录,身份验证仍然无法通过Firebase。
我的代码: ActMain.java
public class ActMain extends AppCompatActivity {
private FirebaseAuth fAuth;
/* Facebook */
private CallbackManager mCallbackManager;
private static final String TAG = ActMain.class.getSimpleName();
/* onCreate */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_main);
// Initialize Firebase Auth
fAuth = FirebaseAuth.getInstance();
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = findViewById(R.id.login_button);
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);
}
});
}
/* Facebook */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Pass the activity result back to the Facebook SDK
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
private void handleFacebookAccessToken(AccessToken token)
{
Log.d(TAG, "handleFacebookAccessToken:" + token);
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
fAuth.signInWithCredential(credential)
.addOnCompleteListener(this, 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");
FirebaseUser user = fAuth.getCurrentUser();
updateUI(user);
}
else
{
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(ActMain.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
我完全迷失在以前继续工作的地方。我可能会做一些非常小的事情,但由于这会导致身份验证失败吗?
答案 0 :(得分:1)
获取当前包的hashkey并将其放在fb开发者控制台上。然后这将有效。
答案 1 :(得分:0)
我有相同的错误,但是问题是我试图在Facebook和google上使用相同的电子邮件登录,因此该电子邮件对于每个用户应该是唯一的。