androidfacebookfacebook-android-sdkfacebook-sdk-4.0android-facebook

ANDROID FACEBOOK SDK-4.0: I get an error when i use "/me?fields=age_range" in my GraphRequest.newGraphPathRequest


  1. I need to get the age_range from facebook.
  2. When i use /me?fields=age_range in my GraphRequest.newGraphPathRequest i get an error.
  3. The error is that graphObject returns null. I've tried using /me and it works i get the correct user data though when i use /me?fields=age_range i get this error.

Testing﹕ {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}}


This is the code i've been trying to fix.

         GraphRequest request = GraphRequest.newGraphPathRequest(accessToken,
                        "/me?fields=age_range",
                        new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse graphResponse) {

                                Log.v("Testing", graphResponse.toString());


                            }
                        });
                request.executeAsync();

Solution

  • You should not put "/me?fields=age_range" as the path in your GraphRequest.

    Instead, only use "/me" as the path, and then create a new Bundle, and put "fields" as the key, and "age_range" as a string value, and set the new bundle as the parameters on the GraphRequest.

    GraphRequest request = ...
    ...
    Bundle params = new Bundle();
    params.putString("fields", "age_range");
    request.setParameters(params);
    request.executeAsync();
    ...