I would like to get user profile data; I'm following this tutorial :
http://code.tutsplus.com/tutorials/quick-tip-add-facebook-login-to-your-android-app--cms-23837
The above tutorial uses registerCallback method like this:
private LoginButton loginButton;
.
.
.
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});
now, How can I implement this method for a custom Button ?
below link use Facebook class, but for me this class undefined!
// Instance of Facebook Class
private Facebook facebook;
http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/
You can use LoginManager to accomplish it without use the LoginButton.
First, you have to create the CallbackManager as usual:
callbackManager = CallbackManager.Factory.create();
Next, you have to register the callback created with LoginManager instance:
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
And finally, you have to invoke the Facebook login with some permissions, for example:
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
Don't forget override the onActivityResult method and call onActivityResult method from the CallbackManager:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With