I am trying to post image on Facebook
using sdk 3.0, but I am facing some problems. If I close the app and reopens the app it always goes in else condition, then it goes in if condition. Do I need to save session
or its already stored??
Session mSession = Session.getActiveSession();
if (mSession != null
&& mSession.getPermissions().contains("publish_actions")) {
postPhoto();
} else {
if (mSession == null) {
Log.d("Facebook", "Session null");
mSession = new Session.Builder(this).setApplicationId(
"xxxxxxxxxxxxxxx").build();
Session.setActiveSession(mSession);
}
if (!mSession.isOpened()) {
Log.d("Facebook", "Session not opened");
Session.OpenRequest sessionRequest = new Session.OpenRequest(
this);
sessionRequest.setPermissions(PERMISSIONS);
sessionRequest.setCallback(statuscallback);
sessionRequest
.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
mSession.openForPublish(sessionRequest);
}
}
StatusCallback statuscallback = new StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
Log.d("Facebook", "Logged in");
postPhoto();
}
if (session.isClosed()) {
Log.d("Facebook", "Logged out");
}
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
Log.d("Facebook", "onActivity Result");
}
What if I need to logout the user??
I tried the following code onDestroy()
if (mSession.isOpened())
mSession.closeAndClearTokenInformation();
whenever I open the app next time it always throws an error at this line if I use the above code in destroy method
mSession.openForPublish(sessionRequest);
Please help guys. Answers/Suggestion would be highly appreciable.
Thanks