Parse Facebook无法收到用户电子邮件和性别

时间:2016-01-03 18:02:17

标签: android facebook parse-platform parsefacebookutils

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

Parse用户JSON没有给我发回电子邮件或性别。我也有研究,但我仍然找不到解决方案(好吧,至少,其他一些仍然返回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部分返回: {“id”:“1234524124124”,“name”:“FbUser NAme”}

Facebook App

2 个答案:

答案 0 :(得分:1)

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

     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();

参考:https://stackoverflow.com/a/32579366/4961962

答案 1 :(得分:-1)

要获取更多用户信息,您必须添加permissoin才能在facebook developer console

访问emailuser_about_me等详细信息
  

在Facebook开发者处选择应用并转到 - >应用详情 - >配置   应用中心权限

enter image description here