好的,所以我正在开发实施facebook登录的应用程序。
我在facebook页面上关注了登录教程,实现很好,并且使用我的facebook帐户和其他一些帐户(我已经在google play上发布了我的应用程序),但不是全部。
Facebook批准了我的权限请求,它们都是实时的,我的应用程序已设置为实时。
用户在检索电子邮件或位置和应用程序崩溃时会收到空指针异常。
我尝试了什么:
如何解决这个问题,我应该检查什么?
这是我的代码:
private final List<String> permissions;
public LoginScreen() {
permissions = Arrays.asList("public_profile", "email","user_location","user_birthday");
}
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setReadPermissions(permissions);
authButton.setFragment(this);
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
// Request user data and show the results
if (mSession == null || isSessionChanged(session)) {
mSession = session;
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Log.v("gj1",Session.getActiveSession().getPermissions().toString());
Log.v("gj1","stateopen");
name=user.getFirstName();
surname=user.getLastName();
Object objEmail=user.getProperty("email");
if(objEmail!=null)
{
mail=user.getProperty("email").toString();
}
else
{
Object objCmail=user.getProperty("contact_email");
if(objCmail!=null)
{
mail=user.getProperty("contact_email").toString();
}
else
{
mail="null@mail.com";
}
}
gender=user.getProperty("gender").toString();
city="N/A";
username=name+surname+user.getId();
password=user.getId();
if(gender.equals("male"))
{
interested="F";
}
else
{
interested="M";
}
if(user.getProperty("birthday")!=null) {
String dateFromDB = user.getProperty("birthday").toString();
username=name+surname+user.getProperty("birthday");
SimpleDateFormat parser = new SimpleDateFormat("MM/dd/yyyy");
try {
Date yourDate = parser.parse(dateFromDB);
Calendar calendar = Calendar.getInstance();
calendar.setTime(yourDate);
Calendar now = Calendar.getInstance();
age = now.get(Calendar.YEAR) - calendar.get(Calendar.YEAR);
} catch (ParseException e) {
e.printStackTrace();
}
}
else
{
age=0;
}
GraphPlace userLocation = user.getLocation();
city = (userLocation != null)? userLocation.toString() : "N/A";
}
}
}
}).executeAsync();
}
} else if (state.isClosed()) {
}
}
错误
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.apps.medico.location_matchup.LoginScreen$5.onCompleted(LoginScreen.java:339)
at com.facebook.Request$1.onCompleted(Request.java:281)
at com.facebook.Request$4.run(Request.java:1666)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
我应该提供更多代码吗?
答案 0 :(得分:3)
您的代码有多种可能无法为用户收到电子邮件,包括但不限于:
有关详细信息,请参阅https://developers.facebook.com/docs/graph-api/reference/v2.2/user。