使用facebook sdk 3.0版&以下是我的代码。我每次都获得id和name值,但是空的电子邮件地址。
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 (user != null) {
Log.i(TAG,"User ID "+ user.getId());
Log.i(TAG,"Email "+ user.asMap().get("email"));
}
}
}).executeAsync();
}
}
});
答案 0 :(得分:0)
无需将权限设置为单独阅读
Session.OpenRequest openRequest = new Session.OpenRequest(LandingPageActivity.this);
openRequest.setPermissions(Arrays.asList...);
openRequest.setCallback(new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
// callback after Graph API response with user
// object
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
string email= user.getProperty("email");
}
}
});
request.executeAsync();
}
});
Session session = new Session(LandingPageActivity.this);
Session.setActiveSession(session);
session.openForRead(openRequest);
参考:click Here