我正在尝试获取登录用户的ID和电子邮件。这是我的代码:
authButton.setReadPermissions(Arrays.asList("basic_info","email"));
// session state call back event
authButton.setSessionStatusCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.i(TAG,"Access Token"+ session.getAccessToken());
Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,Response response) {
if (response != null) {
Log.i(TAG,"User ID "+ user.getId());
Log.i(TAG,"Email "+ user.asMap().get("email"));
}
}
});
}
}
});
直到这里一切顺利
Log.i(TAG,"Access Token"+ session.getAccessToken());
我可以看到访问令牌,但未调用onComplete
方法,并且我没有获得任何用户信息。
我做错了什么?
答案 0 :(得分:2)
尝试
if (user != null)
而不是
if (response != null)
或尝试
Request.newMeRequest(...).executeAsync();