On Android
I followed the Session
login sample to create the login flow for an app I am working on. The problem I'm having is on a few devices if the Facebook
app is not installed when the user logs in through Facebook
via the WebDialog
, then the page seems to redirect back to login page.
I'm using Facebook
sdk 3.0.1, I've also upgraded to 3.5 to see if that would fix my issue, it did not. The sample provided in the 3.0.1 sdk doesn't even work and the sample included with the 3.5 sdk performs exactly like my app.
I have tried this code below on other devices that do not have the Facebook
app installed and they work just fine. But when I try this on my Nexus 7 (4.3 installed) I run into the problem described above.
Any ideas?
private Session.StatusCallback statusCallback = new SessionStatusCallback();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void Login() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
private void Logout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
//check session and see if we are logged in.
}
}
Edit: An update to this. I've tried this same example/app on a Samsung Galaxy S4 (Running 4.2.2) Model number SGH-I337, and it is not working on this device either. It does something a little different in that it will let you hit ok if you have approved the app on Facebook
or it will let you go through the motions to allow the app through Facebook
, but then it will display a page saying
"Error Not Logged In: You are not logged in. Please login and try again."
Edit 2:In an attempt to verify this is not exclusive to our app, we installed Candy Crush and got the same error.