简体   繁体   中英

Parse Facebook unable get user email and gender

Currently, I am using this tutorial to create the facebook login. " https://github.com/ParsePlatform/ParseUI-Android "

The Parse user JSON didn't return me an email or gender. I also have research around but I still can't find the solution (well, at least, some other still returning null). Anyone can explain the reason and how to solve it?

    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 Section return: {"id":"1234524124124","name":"FbUser NAme"}

Facebook应用程式

I just found the answer. I just need to set the parameter so I can get the data I want.

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

Reference: https://stackoverflow.com/a/32579366/4961962

for more user info you have to add permissoin to access those detail like email , user_about_me at facebook developer console

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM