Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';无法获取Facebook ID和电子邮件_Java_Android_Facebook_Facebook Authentication - Fatal编程技术网

Java Can';无法获取Facebook ID和电子邮件

Java Can';无法获取Facebook ID和电子邮件,java,android,facebook,facebook-authentication,Java,Android,Facebook,Facebook Authentication,我面临以下问题:授权后需要获得FB id和电子邮件。这是我的密码: @Override public void onSuccess(LoginResult loginResult) { final String[] email = new String[1]; final String[] id = new String[1]; GraphRequest request =

我面临以下问题:授权后需要获得FB id和电子邮件。这是我的密码:

@Override
            public void onSuccess(LoginResult loginResult) {

                final String[] email = new String[1];
                final String[] id = new String[1];

                GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        (object, response) -> {
                            try {
                                email[0] = object.getString(FB_EMAIL_PERMISSION);
                                id[0] = object.getString(FB_ID_PERMISSION);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            response.getRawResponse();
                        });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,email");
                request.setParameters(parameters);
                request.executeAsync();

                Bundle bundle = new Bundle();
                bundle.putString(EXTRA_TOKEN, loginResult.getAccessToken().getToken());
                bundle.putString(EXTRA_EMAIL, email[0]);
                bundle.putString(EXTRA_ID, id[0]);

                mPresenter.saveUserData(bundle);
            }
但是当我运行我的应用程序时,我不会得到这个字段。我签入了调试器和部件

GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        (object, response) -> {
                            try {
                                email[0] = object.getString(FB_EMAIL_PERMISSION);
                                id[0] = object.getString(FB_ID_PERMISSION);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            response.getRawResponse();
                        });
一点也不叫。我不明白为什么会这样。那么,出了什么问题,我该如何解决

UPD

也许,也许这会有帮助,下面是整个fb逻辑:

mCallbackManager = CallbackManager.Factory.create();
        mFacebookButton.setReadPermissions(Collections.singletonList(FB_EMAIL_PERMISSION));
        mFacebookButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                final String[] email = new String[1];
                final String[] id = new String[1];

                GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        (object, response) -> {
                            try {
                                email[0] = object.getString(FB_EMAIL_PERMISSION);
                                id[0] = object.getString(FB_ID_PERMISSION);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            response.getRawResponse();
                        });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,email");
                request.setParameters(parameters);
                request.executeAsync();

                Bundle bundle = new Bundle();
                bundle.putString(EXTRA_TOKEN, loginResult.getAccessToken().getToken());
                bundle.putString(EXTRA_EMAIL, email[0]);
                bundle.putString(EXTRA_ID, id[0]);

                mPresenter.saveUserData(bundle);
            }
以下是权限的值:

private static final String FB_EMAIL_PERMISSION = "email";
private static final String FB_ID_PERMISSION = "id";

您是否向您的facebook登录按钮添加了权限

fbLoginButton.setPermissions(Arrays.asList("public_profile,email,user_birthday"));
这就是我使用它的方式 我不确定
FB\u EMAIL\u PERMISSION
FB\u ID\u PERMISSION

 final GraphRequest request = GraphRequest.newMeRequest(
                AccessToken.getCurrentAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {
                        try {
                            String id = "", user_email = "", name = "";
                            Log.d("EHREIUIU", String.valueOf(object));
                            if (response.getJSONObject() != null) {
                                JSONObject data = response.getJSONObject();
                                if (data.has("id"))
                                    id = data.getString("id");
                                if (data.has("email"))
                                    user_email = data.getString("email");
                            }
                            getOneSignalToken();
                            socialLogin(user_email, name, null, id, "facebook");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });

我有这样一行:
mFacebookButton.setReadPermissions(Collections.singletonList(FB_EMAIL_PERMISSION)),但当我添加您的变体时,它并没有解决我的问题。setReadPermissions不支持此问题
 final GraphRequest request = GraphRequest.newMeRequest(
                AccessToken.getCurrentAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {
                        try {
                            String id = "", user_email = "", name = "";
                            Log.d("EHREIUIU", String.valueOf(object));
                            if (response.getJSONObject() != null) {
                                JSONObject data = response.getJSONObject();
                                if (data.has("id"))
                                    id = data.getString("id");
                                if (data.has("email"))
                                    user_email = data.getString("email");
                            }
                            getOneSignalToken();
                            socialLogin(user_email, name, null, id, "facebook");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });