Question

I would like to get name from user id with Graph API, I already have the user id from a SELECT query

 https://graph.facebook.com/"+id+"?fields=name

I don't know how to call a http/url query and retrieve the data?

Was it helpful?

Solution 2

I was able to resolve the issue with this request, I got the solution from this [link]Facebook android sdk how to get the number of likes for a given page

the "id" is from the first query of the actor_id

    Bundle params = new Bundle();
    params.putString("id", id);
    params.putString("fields", "name");

    Request request = new Request(session, "search", params, HttpMethod.GET, new Request.Callback() {
    public void onCompleted(Response response) { try {
  JSONObject res = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
                                    final String name = (String) res.get("name");

OTHER TIPS

Since you are using the Android SDK, you can make the Graph API calls like this-

Bundle params = new Bundle();
params.putString("fields", "name");

final String requestId = {actor-id};

Request request = new Request(session, requestId, params, HttpMethod.GET, new Request.Callback() {
   public void onCompleted(Response response) {
       GraphObject graphObject = response.getGraphObject();
       FacebookRequestError error = response.getError();
       if (graphObject != null) {
          if (graphObject.getProperty("id") != null) {
              String name = (String)graphObject.getProperty("name");
          }
      }
   }
});

Request.executeAndWait(request);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top