不从 Facebook 检索电子邮件和位置 - 权限已获批准

Not retrieving email and location from facebook - permissions are approved

好的,所以我正在开发实现 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.onCompleted(LoginScreen.java:339)
at com.facebook.Request.onCompleted(Request.java:281)
at com.facebook.Request.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)

在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我应该提供更多代码吗?

您的代码没有收到用户的电子邮件有多种可能,包括但不限于:

  • 用户未授予您电子邮件权限(他们可以在身份验证流程中删除权限,或者他们可以稍后从 Facebook 网站或应用程序中删除该权限)
  • 用户可能没有有效的电子邮件地址(有一些方法可以在不提供或验证电子邮件的情况下注册 Facebook)

有关详细信息,请参阅 https://developers.facebook.com/docs/graph-api/reference/v2.2/user