现在我正在通过 facebook 登录。为此,我使用的是 android sdk 3.0。在我的应用程序中,我必须获取用户的电子邮件 ID。我正在使用以下代码获取电子邮件 ID,但我无法获取。如果我做错了,你能给我任何建议吗?每次我要去别的地方。
loginButton = (LoginButton) findViewById(R.id.authButton);
// for error on login
loginButton.setOnErrorListener(new OnErrorListener() {
public void onError(FacebookException error) {
Log.i(TAG, "Error " + error.getMessage());
}
});
// loginButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
// set permission list, Don't forget to add email
loginButton.setReadPermissions(Arrays.asList("basic_info", "email"));
// session state call back event
loginButton.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.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
Log.d(TAG, "User ID " + user.getId());
Log.d(TAG,
"Email "
+ user.asMap().get(
"email"));
}
}
});
} else {
Log.d("session is not valid", ""
+ Session.getActiveSession().getState());
}
}
});