有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在安卓中从facebook获取用户性别和生日

我试图从Facebook上获取当前登录用户的性别和生日,但我总是得到(id、电子邮件、姓名),我已经搜索了与此相关的所有内容,但我没有得到确切的信息,因为我正在寻找。在下面的代码中,我尝试了一些不起作用的东西

facebookLoginButton  = (LoginButton)view .findViewById(R.id.fragment_login_facebook);
        facebookLoginButton.setFragment(this);
callbackManager = CallbackManager.Factory.create();

facebookLoginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
        callbackManager = CallbackManager.Factory.create();

    facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        private ProfileTracker mProfileTracker;
        @Override
        public void onSuccess(LoginResult loginResult) {


            String accessTocken = loginResult.getAccessToken().getToken().toString();

            Log.v("TAG", "Access Token " + loginResult.getAccessToken().getToken());
            GraphRequest request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {

                            try {
                                String email = object.getString("birthday");
                                String name = object.getString("gender");
                                Toast.makeText(getActivity().getApplicationContext(),email + " " + name ,Toast.LENGTH_SHORT).show();
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });

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



            if (com.facebook.Profile.getCurrentProfile() == null){
                mProfileTracker = new ProfileTracker() {
                    @Override
                    protected void onCurrentProfileChanged(com.facebook.Profile oldProfile, com.facebook.Profile currentProfile) {
                        mProfileTracker.stopTracking();
                    }
                };
                mProfileTracker.startTracking();
            } else {
                com.facebook.Profile profile = com.facebook.Profile.getCurrentProfile();
            }

            try {
                URL image_value = new URL("http://graph.facebook.com/" + loginResult.getAccessToken().getUserId() + "/picture?type=large");
                Log.v(Constants.TAG, image_value + "");
            } catch (Exception e) {
            }
        }

        @Override
        public void onCancel() {
            Log.e("TAG", "wrong");
        }

        @Override
        public void onError(FacebookException error) {
            Log.e("TAG", "wrong");
        }
    });

其中facebookLoginButton是LoginButton,callbackManager是callbackManager 请先帮我谢谢


共 (1) 个答案

  1. # 1 楼答案

    • Facebook gender&birthday需要应用程序审查

    Apps that Require App Review

    Your app requires review if it uses the following functionality:

    Facebook Login and also asks for a person's birthday, location, hometown, gender, age range, or link to profile

    • 有关更多详细信息,请查看link