I've read through the documentation and source code and other relevant questions here, but I am still having an issue authorizing/logging into my app using the Facebook SDK 3 for Android.
I do not want to use the "Login" button provided.
Here is the relevant code:
On the Activity.onCreate I start the session:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Session session = Session.getActiveSession();
mPrefs = getSharedPreferences("facebook_storage", MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (session == null) {
if (access_token != null) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", null);
editor.commit();
AccessToken accessToken = AccessToken.createFromExistingAccessToken(access_token, null, null, null, null);
session.open(accessToken, this);
} else {
session = new Session(getApplicationContext());
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(this));
} else if (session.getState().equals(SessionState.CREATED)) {
System.out.println("Session created, no token. I guess");
session.openForRead(new Session.OpenRequest(this).setCallback(this));
}
}
This triggers:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
Which in turn triggers the next block, entering at if (session.isOpened()):
public void call(Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
if (session == null) {
MmfLogger.error("FacebookLogin session == null in call()");
} else if (session.isOpened()) {
System.out.println("Session.StatusCallback success: " + session.getState());
Request request = new Request(session, REQUEST_FIELDS, null, null, this);
request.executeAsync();
}
if (!session.isOpened()) {
System.out.println("session failed to open");
}
if (session.isOpened() && session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
Request request = new Request(session, REQUEST_FIELDS, null, null, this);
request.executeAsync();
} else if (session.isOpened() && session.getState().equals(SessionState.CREATED)) {
System.out.println("session isOpened and state is created");
}
}
And from here I get and error stating I need an active token. However, before the Request is made, I can see the token. The session has one. Where am I going wrong?
Thank you for your time.