我想在我的Android应用程序中集成Facebook登录。现在我可以使用Facebook登录我的应用程序,但现在我只能 id 和 名称 。我添加了权限“email”,“public_profile”,“user_friends”。在我的Facebook应用程序中,其显示为 电子邮件,public_profile,user_friends 位于已批准的项目中。这是我用于Facebook登录的代码。
我正在使用loginWithFacebook()
功能进行Facebook登录,
public void loginWithFacebook() {
session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}else
Session.openActiveSession(this, true, Arrays.asList("email", "public_profile", "user_friends"),this.callback);
}
// Facebook会话状态回调
private Session.StatusCallback callback = new Session.StatusCallback() {
@SuppressWarnings("deprecation")
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
// onSessionStateChange
private static void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i("FB", "Logged in...");
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
try {
String email = null, id = null, first_name = null, last_name = null, gender = null, name = null;
Toast.makeText(context, user.asMap().toString(), Toast.LENGTH_LONG).show();
if(user.asMap().containsKey("email"))
email = (String) user.asMap().get("email");
if(user.asMap().containsKey("id"))
id = (String) user.asMap().get("id");
if(user.asMap().containsKey("name"))
name = (String) user.asMap().get("name");
if(user.asMap().containsKey("first_name"))
first_name = (String) user.asMap().get("first_name");
if(user.asMap().containsKey("last_name"))
last_name = (String) user.asMap().get("last_name");
if(user.asMap().containsKey("gender"))
last_name = (String) user.asMap().get("gender");
System.out.println("\n*****\nemail " + email+ "\n id " + id+ "\nFirstName " + first_name+ "\nLastName : " + last_name+ "\ngender : " + gender);
} catch (Exception e) {
e.printStackTrace();
}
}
}).executeAsync();
}else if (state.isClosed()) {
Log.i("FB", "Logged out...");
}
}
由于