我遇到了一个问题-我正在开发一个使用Facebook登录的应用程序,而且我还需要获取用户数据,因为某种原因,我无法在request.newmerequest中接收此数据,因为它的未完成方法从未被调用。我在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...");
    }
}

最佳答案

这里的问题是,您已经创建了一个请求,但您没有对其调用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

07-26 09:30