【问题标题】:Parse Facebook unable get user email and gender解析 Facebook 无法获取用户电子邮件和性别
【发布时间】:2016-01-03 18:02:17
【问题描述】:

目前,我正在使用本教程来创建 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 名称"}

【问题讨论】:

  • 你配置@facebook 控制台了吗
  • 我已经在 manifest 中配置了 facebook。我需要初始化 facebook SDK 吗?目前只能获取id和name。
  • 你需要请求你想要的字段。
  • @WizKid 我已获得许可。
  • 这不是我说的。权限和字段是两个完全不同的东西。但我现在知道你找到了它

标签: android facebook parse-platform parsefacebookutils


【解决方案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

【讨论】:

    【解决方案2】:

    如需更多用户信息,您必须添加权限才能访问这些详细信息,例如 emailuser_about_me facebook developer console

    在 facebook 开发者处选择应用程序,然后转到 -> 应用程序详细信息 -> 配置 应用中心权限

    【讨论】:

    • 我只是配置了应用中心权限,但是好像不行
    猜你喜欢
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多