I (think I) followed Facebook tutorial but I can't get it work properly. I'm trying to login via FB and then get info about the user. I have:
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
System.out.println("GOOD");
if (session.isOpened()) {
System.out.println("AWESOME");
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
m_user = user;
System.out.println("Hello " + user.getName());
}
});
}
}
And then:
public void onBtnFacebookClick(final View v) {
Session session = Session.getActiveSession();
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));
}
}
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
But it seems that "AWESOME" is never printed ("GOOD" is printed) eventhough I managed to login to FB.
Or maybe I don't understand what session.isOpened()
means?
Ok it's working now. I had two problems. One is incorrect hash key which I fixed following these instructions. The other is that I didn't know I had to override this method:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession()
.onActivityResult(this, requestCode, resultCode, data);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With