I’m trying to integrate the Facebook Android SDK in my app, but I can’t seem to get the most basic authentication working. I’ve got my project setup, my Facebook App ID, everything as required.
I kick off the Facebook authentication with a simple OnClickListener():
signIn_Facebook.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Log.i("MyTag", "Facebook authorize about to start.");
facebook.authorize(SignIn.this, new FacebookLoginDialogListener());
}
});
My problem is that none of the methods in the DialogListener ever get called:
private class FacebookLoginDialogListener implements DialogListener {
public void onComplete(Bundle values)
{
Log.i("MyTag", "Facebook authorize complete.");
}
@Override
public void onFacebookError(FacebookError error) {
Log.i("MyTag", "Facebook authorize facebook error.");
}
@Override
public void onError(DialogError e)
{
Log.i("MyTag", "Facebook authorize dialog error.");
}
@Override
public void onCancel()
{
Log.i("MyTag", "Facebook authorize cancel.");
}
}
When this code runs on the app, the Facebook dialog opens up, you can sign in, and then it just closes – no errors – however none of the log message (or breakpoints) in the FacebookLoginDialogListener class ever get called.
I feel as though I’m missing something really obvious. Thanks…
SOLVED
Just needed to add:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
facebook.authorizeCallback(requestCode, resultCode, data);
}
try this:
private Facebook mFb;
private String[] mPermissions;
mFb.authorize(mActivity, mPermissions, new LoginDialogListener());
If you want an example check out https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/LoginButton.java
Anything else, just ask 😉