在我的应用程序中,我使用Parse.com和Facebook登录,Facebook登录正在运行,我现在正在尝试保存签名用户的电子邮件。我是这样做的:
Request.newMeRequest(ParseFacebookUtils.getSession(), 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").toString();
Log.i(TAG, email);
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.put("email", email);
currentUser.saveInBackground();
}
}
}).executeAsync()
但是当我运行时,我在此行java.lang.NullPointerException
获取currentUser.put("email", email);
但是我在此之前记录了电子邮件并且它不是null并且我的用户类中有一个关于解析的电子邮件属性,所以我不是明白为什么这个?
这里是设置FB登录之前的代码,您应该需要它并且它正在运行但是以防万一。
public void onLoginClick(View v) {
progressDialog = ProgressDialog.show(LoginActivity.this, "", "Logging in...", true);
final List<String> permissions = Arrays.asList("public_profile", "email");
// NOTE: for extended permissions, like "user_about_me", your app must be reviewed by the Facebook team
// (https://developers.facebook.com/docs/facebook-login/permissions/)
ParseFacebookUtils.logIn(permissions, this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
progressDialog.dismiss();
if (user == null) {
Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Log.d(TAG, "User signed up and logged in through Facebook!");
showSelectSchoolActivity();
} else {
Log.d(TAG, "User logged in through Facebook!");
showMainActivity();
}
}
});
感谢您的帮助:)
答案 0 :(得分:0)
用于检查响应,您应始终使用(err == null)作为成功的条件。只有在收到服务器的响应并且err == null之后,您才能检查当前用户。您还应该检查err!= null的时间。然后从err.getCode()获取错误消息并检查错误代码是什么。