我遇到了一个问题 - 我正在使用facebook登录开发一个应用程序,而且我需要获取用户数据,因为某种原因我无法在Request.newMeRequest中收到此数据,因为它的onCompleted方法从未被调用过。我在logcat中只看到登录/注销消息。我做错了什么?
这是我的代码:
private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i("QWE", "Logged in...");
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
Log.i("QWE","onCompleted");
if (user != null) {
Log.i("QWE", "User is "+ user.getUsername());
}
}
});
} else if (state.isClosed()) {
Log.i("QWE", "Logged out...");
}
}
答案 0 :(得分:28)
这里的问题是您已经创建了一个请求,但是您没有在其上调用executeAsync,因此永远不会发出请求。尝试:
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
Log.i("QWE","onCompleted");
if (user != null) {
Log.i("QWE", "User is "+ user.getUsername());
}
}
}).executeAsync(); // <--- CHANGE IS HERE