无法从facebook Graph api收到电子邮件

时间:2016-12-08 06:33:17

标签: android facebook

我在应用程序中实现了Facebook并从图形api中获取了名称,电子邮件和ID,现在我无法从图形api收到电子邮件,我通过了id,名称,电子邮件字段但只获得了id,名称但没有发送电子邮件。这是改变的来自facebook的任何隐私政策。 我在这里使用https://graph.facebook.com/me?access_token=(token& fields = id,name,email

1 个答案:

答案 0 :(得分:0)

尝试成功运行

 private void facebookLogin() {

            mFaceBookloginButton = (LoginButton) findViewById(R.id.login_button);
            mFaceBookloginButton.setReadPermissions("public_profile");
            mFaceBookloginButton.setReadPermissions("email");
            callbackManager = CallbackManager.Factory.create();


            mFaceBookloginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    MyLog.debug("Name" + loginResult.getAccessToken(), ActivityLogin.class);
                    Profile profile = Profile.getCurrentProfile();

                    if (profile != null) {
                        MyLog.debug("Pic Url" + profile.getProfilePictureUri(200, 200), ActivityLogin.class);
                        MyLog.debug("User Name" + profile.getFirstName(), ActivityLogin.class);
                        MyLog.debug("User Email" + profile.getLastName(), ActivityLogin.class);
                    }
                    GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {

                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            FacebookUser facebookUser = null;
                            try {
                                if (object != null) {
                                    facebookUser = new FacebookUser();

                                    if (object.has("id")) {
                                        facebookUser.setId(object.getString("id"));
                                    }
                                    if (object.has("first_name")) {
                                        facebookUser.setFirst_name(object.getString("first_name"));
                                    }
                                    if (object.has("last_name"))
                                        facebookUser.setLast_name(object.getString("last_name"));
                                    if (object.has("email"))
                                        facebookUser.setEmail(object.getString("email"));
                                }


                                if (facebookUser != null) {
                                    hitSocialLogin(facebookUser);
                                    LoginManager.getInstance().logOut();
                                }
                            } catch (Exception e) {
                                MyLog.printException(e);
                            } finally {
                                LoginManager.getInstance().logOut();
                            }
                        }
                    });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id, first_name, last_name, email,gender, birthday, location"); // Parámetros que pedimos a facebook
                    request.setParameters(parameters);
                    request.executeAsync();

                }

                @Override
                public void onCancel() {
                    MyLog.debug("on Cancel", ActivityLogin.class);
                }

                @Override
                public void onError(FacebookException exception) {
                    MyLog.debug("on Cancel" + exception, ActivityLogin.class);
                }
            });
        }