简体   繁体   中英

FacebookSDK Request.newMeRequest never been called

I've got a problem - I'm developing an app with facebook login and also I need to get User data, for somewhat reason I cant receive this data in Request.newMeRequest, because its onCompleted method never been called. I see in logcat only Logged in/out messages. What I'm doing wrong?

Here is my code:

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...");
    }
}

The problem here is that you've created a request, but you're not calling executeAsync on it, so the request is never made. Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM