Problem Sign in of Facebook with Android studio

3

I am trying to allow the sign in through Facebook Login but the problem is repeated again and again. Once validated by Facebook the email and password and authorized to see the public information and the user's email, I return to my signin window but does not go through onSuccess.

I think the facebook app I have it well created. I got the KeyHash with the tutorial code, the package is detected in google play, the id is correct ...

The code used is the following:

public class SignInActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {

LoginButton loginButton;
private CallbackManager callbackManager;

 @Override

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    setContentView(R.layout.signinactivity);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("email");


    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

    @Override
        public void onSuccess(LoginResult loginResult) {

    Log.d("vfd", "entra onSuccess");

        }

        @Override
        public void onCancel() {
            Log.d("vfd", "cancela");
        }

        @Override
        public void onError(FacebookException exception) {
            Log.v("LoginActivity", exception.getCause().toString());
        }
    });
}
    
asked by Javier Pintor 26.02.2016 в 21:18
source

1 answer

3

To what I see, I just need to add the onActivityResult. Try this code.

public class SignInActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {

  LoginButton loginButton;
  private CallbackManager callbackManager;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.signinactivity);
    FacebookSdk.sdkInitialize(getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("email");

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

    @Override
    public void onSuccess(LoginResult loginResult) {

        Log.d("vfd", "entra onSuccess");

    }

    @Override
    public void onCancel() {
        Log.d("vfd", "cancela");
    }

    @Override
    public void onError(FacebookException exception) {
       Log.v("LoginActivity", exception.getCause().toString());
    }
  });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data); 
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
    
answered by 27.02.2016 / 01:30
source