解析Facebook无法获取用户邮箱和性别

Parse Facebook unable get user email and gender

目前,我正在使用本教程创建 facebook 登录。 “https://github.com/ParsePlatform/ParseUI-Android

Parse 用户 JSON 没有 return 给我电子邮件或性别。我也有研究,但我仍然找不到解决方案(好吧,至少,其他一些仍然 returning null)。谁能解释一下原因以及如何解决?

    facebookLoginButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        loadingStart(false); // Facebook login pop-up already has a spinner
        if (config.isFacebookLoginNeedPublishPermissions()) {
          ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(),
                  Arrays.asList(
                          "public_profile", "email"), facebookLoginCallbackV4);
          Log.i("fbUser","Publish");
        } else {
          ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(),
                  Arrays.asList( "public_profile", "email"), facebookLoginCallbackV4);

          Log.i("fbUser", "Read");
        }
      }
    });

 private LogInCallback facebookLoginCallbackV4 = new LogInCallback() {
    @Override
    public void done(ParseUser user, ParseException e) {
      if (isActivityDestroyed()) {
        return;
      }

      if (user == null) {
        loadingFinish();
        if (e != null) {
          showToast(R.string.com_parse_ui_facebook_login_failed_toast);
          debugLog(getString(R.string.com_parse_ui_login_warning_facebook_login_failed) +
                  e.toString());
        }
      } else if (user.isNew()) {
        GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
              @Override
              public void onCompleted(JSONObject fbUser,
                                      GraphResponse response) {
                  /*
                    If we were able to successfully retrieve the Facebook
                    user's name, let's set it on the fullName field.
                  */
                ParseUser parseUser = ParseUser.getCurrentUser();
                if (fbUser != null && parseUser != null && fbUser.optString("name").length() > 0) {
                  Log.i("FbUSer", response.getJSONObject().toString());


                  Log.d("FbUSer-Email",fbUser.optString("email"));
                  Log.i("FbUSer-gender",fbUser.optString("gender"));
                  parseUser.put(USER_OBJECT_NAME_FIELD, fbUser.optString("name"));

                  parseUser.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                      if (e != null) {
                        debugLog(getString(
                                R.string.com_parse_ui_login_warning_facebook_login_user_update_failed) +
                                e.toString());
                      }
                      loginSuccess();
                    }
                  });
                }
                loginSuccess();
              }
            }
        ).executeAsync();
      } else {
        loginSuccess();
      }
    }
  };

Logcat 部分 return: {"id":"1234524124124","name":"FbUser NAme"}

要获得更多用户信息,您必须添加访问这些详细信息的权限,例如 emailuser_about_me facebook developer console

select app at facebook developer and go -> app details -> Configure App Center Permissions

我刚刚找到了答案。我只需要设置参数就可以得到我想要的数据。

     GraphRequest request = GraphRequest.newMeRequest(...);
     Bundle parameters = new Bundle();
                            parameters.putString("fields","id,name,link,email,first_name,last_name,gender");
                            request.setParameters(parameters);
                        request.executeAsync();

参考: