I am writing an Android application that should upload photos to Facebook.
Everything works fine except for one. When I first called the Facebook.authorize () method, a Facebook dialog box was opened with the requested permissions and the Allow / Do Not Allow buttons. Everything is good. But when I launch my application for the second session, I have the same dialog, but with a message that my application has already allowed and offered to click OK.
Is there any way to avoid this second dialogue? Should I skip the authorization method in some conditions?
I tried calling the Facebook.isSessionValid () method before logging in, but that didn't help.
Here is my simplified code:
mFacebook = new Facebook(APPLICATION_ID); mFacebookAsync = new AsyncFacebookRunner(mFacebook); if (mFacebook.isSessionValid()) { uploadPictureFile(); } else { mFacebook.authorize(this, new String[] {"publish_stream"}, new Facebook.DialogListener() { @Override public void onFacebookError(FacebookError e) { Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); finishWithResultCode(RESULT_CANCELED); } @Override public void onError(DialogError e) { Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook dialog error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); finishWithResultCode(RESULT_CANCELED); } @Override public void onComplete(Bundle values) { uploadPictureFile(); } @Override public void onCancel() {Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook authorization cancelled.", Toast.LENGTH_LONG).show(); finishWithResultCode(RESULT_CANCELED); } }); }
And here is my onActivityResult method:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { mFacebook.authorizeCallback(requestCode, resultCode, data); }
Any help appreciated. Thanks.
android facebook sdk single-sign-on
Alexey Erzyamkin
source share