samatovS
samatovS

Reputation: 432

How to retrieve education and work from Facebook graph api android

I've been googling but failed to find a comprehensive answer on how to access my profiles education and work fields. All I am interested in is the name of the school and the company user works for. I tried using GraphRequest.newMeRequest() method. here's my code:

 private void getUserInfoFromResult(LoginResult loginResult){
        GraphRequest request=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject object, GraphResponse response) {
                try{
                    JSONObject userObject=response.getJSONObject();

                    String firstName=userObject.getString("first_name");
                    String lastName=userObject.getString("last_name");

                    JSONArray education=userObject.getJSONArray("education");
                    JSONArray work=userObject.getJSONArray("work");
                }
                catch (JSONException e){

                }
            }
        });

        Bundle parameters=new Bundle();
        parameters.putString("fields","first_name,last_name,education,work");
        request.setParameters(parameters);
        request.executeAsync();
    }

I am able to retrieve users first and last name however the response object doesn't return the education and work fields.

Upvotes: 0

Views: 344

Answers (1)

Chirag.T
Chirag.T

Reputation: 756

Also add permission for access education details. like...

LoginManager.getInstance().logInWithReadPermissions(Login.this, Collections.singletonList("public_profile, email, user_birthday, user_education_history, user_location"));

Upvotes: 1

Related Questions