我(想我)遵循了 Facebook 教程,但我无法让它正常工作。我正在尝试通过 FB 登录,然后获取有关用户的信息。我有:
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());
}
});
}
}
接着:
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);
}
}
但似乎“AWESOME”从未被打印出来(“GOOD”被打印出来)即使我设法登录到 FB。或者我不明白什么session.isOpened()
意思?