Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user Gender and birthday from facebook in android

I am Trying to get gender and birthday of current login user from Facebook, but I always getting (id, email, name) I have search everything related to this but I didn't get exactly that for I am looking. below code, I have Trying that's not working.

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");
        }
    });

Where facebookLoginButton is LoginButton and callbackManager is CallbackManager Please help me thanks in advance.

like image 404
Rishi Avatar asked Jun 28 '18 23:06

Rishi


People also ask

How can I get my Facebook API gender?

You can get the gender of any user using Open Graph even without any access_token. GET https://graph.facebook.com/userid json_decode the data gender will be in the `gender` element of the returned array.

How to get gender and birthday info from app?

What the app do is sign in (Sign In API included name and email) first, then request birthday & gender (People API) authentication, and save it to SharedPreferences for reuse on next launch. Finally it will print basic info and advanced (gender & birthday) info.

How can I See my Friend's birthday on the app?

The only way to see birthdays on the app is by searching that person's name and going to their profile If they’ve enabled their Facebook friends or the public to see their birthday then you should be able to see it Facebook has made it impossible to download your friend’s birthday information from Facebook due to data privacy concerns.

What does user_gender mean on Facebook app review?

Requires App Review. The user_gender permission allows your app to read a person's gender as listed in their Facebook profile. The allowed usage for this permission is to render pronouns and to personalize a person's experience based on gender, for example dating, shopping and fashion apps.

How to create a Facebook app on Android?

Enter Application display name and your contact email address . Then click on Create App ID . 6. At front of Facebook Login click on Get Started. 7. On Choose Platform Window click on Android . 8. Now skip to the 2nd step and open your Project’s build.gradle (Module:app) file.


1 Answers

  • Facebook gender & birthday needs app review.

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

  • Check the link for more details.
like image 82
Khaled Lela Avatar answered Sep 27 '22 22:09

Khaled Lela