I also spent several hours finding a solution for this.
Share your experience below:
First, I request a fb session, requesting user data with the following permissions:
session.openForRead(new com.facebook.Session.OpenRequest( LoginActivity2.this).setPermissions( Arrays.asList("public_profile","email")).setCallback( statusCallback));
In a valid session, I then invoke the request using this code block:
new Request( session, graphPath, bundle, HttpMethod.GET, new Request.Callback() { @Override public void onCompleted(Response response) { Log.v(TAG, "response = xx" + response.toString()); String age_min = ""; String age_max = ""; GraphObject graphObject = response.getGraphObject(); Map<String, Object> stateMap = graphObject.asMap(); try { JSONObject age_range = (JSONObject) stateMap.get("age_range"); age_min = age_range.getString("min"); age_max = age_range.getString("max"); } catch (Exception e) { Log.v(TAG, "error in parsing age_range here = " + e.getMessage()); } Log.v(TAG, "logging the age_range min here = " + age_min); Log.v(TAG, "logging the age_range max here = " + age_max); if (!"".equalsIgnoreCase(age_max)) { if ("18".equalsIgnoreCase(age_max)) { age_range = "0-18"; } else if ("21".equalsIgnoreCase(age_max)) { age_range = "18-21"; } } else if (!"".equalsIgnoreCase(age_min)) { if ("18".equalsIgnoreCase(age_min)) { age_range = "18-21"; } else if ("21".equalsIgnoreCase(age_min)) { age_range = "21-100"; } } Log.v(TAG, "and here in FB2 the age_range is = " + age_range); } } ).executeAndWait();
Where:
session (string) -> current and current session
graphPath (string) -> this is fb userID (maybe "I", but I have not tested this, please let me know if "I" works.
bundle โ is the K, V parameter that you request, in case of age_range this is:
Bundle bundle = new Bundle(); bundle.putString("fields", "age_range");
Note that the request code block (at least in my case) was executed inside the doinBackground of the internal AsyncTask) -> thus, my use of the executeAndWait () method instead of executeAsync ().
Hope this helps someone with the same issue. Thanks!