I have the following code. It is a simple test of the callback function of the LoginButton in Facebook's Android API.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setReadPermissions("email");
loginButton.setReadPermissions("public_profile");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e("SUCCESS", "LOGIN SUCCESSFUL");
}
@Override
public void onCancel() {
Log.e("CANCEL", "Cancelled");
}
@Override
public void onError(FacebookException e) {
Log.e("ERROR", "Facebook Exception");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
The only problem is that whenever I click the loginButton, a dialog appears and disappears for a brief moment, and then the logcat prints out the "CANCEL" text. I cannot seem to fix this error, and I'm not clicking cancel, because that dialog simply shows up and immediately disappears.
Please help me fix this?
Aucun commentaire:
Enregistrer un commentaire