I’m trying to integrate facebook login on my android app. I found a lot of examples on internet, but now I have the following problem and I can’t find a solution.
After facebook.authorize finish work, the oncomplete method is never called.
If I use the facebook.authorize with Facebook.FORCE_DIALOG_AUTH, in this case the oncomplete method is called and I can save the access_token.
I attach a snipped of my code.
Can anyone help me to solve this problem?
if(!facebook.isSessionValid()) {
facebook.authorize(Login.this, new String[] {"publish_stream","read_stream", "offline_access"}, //Facebook.FORCE_DIALOG_AUTH,
new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {Log.e("FB:","Facebook Error" );}
@Override
public void onError(DialogError e) {Log.e("FB:","Error" );}
@Override
public void onCancel() {}
});
}
Thanks
Simo
Make sure that you implemented onActivityResult()
properly as stated in the official documentation:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
Tags: androidandroid, facebook