Question

How do I get the name of the actor_id in the same request, and display all the information from the table and the "name"?

 SELECT permalink,actor_id FROM stream WHERE source_id=me()

then I want the name of the actor_id

I know I can use the actor_id results and get the name in a new request

 SELECT name FROM user WHERE uid=actor_id

but, I need to display the permalink and the name together.

How do I get results from

 https://graph.facebook.com/user_id?fields=name

Can I do a URL/https request to display the name with actor_id results I got?

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

You can make the multiple query using RequestBatch-

ArrayList<Request> requests = new ArrayList<Request>();

// Request-1
String streamQuery = "SELECT permalink,actor_id FROM stream WHERE source_id=me()";
Bundle args1 = new Bundle();
args1.putString("q", streamQuery);

Request request1 = new Request(session, "fql", args1, HttpMethod.GET);

request1.setCallback(new com.facebook.Request.Callback() {
     @Override
     public void onCompleted(Response response) {
         GraphObject graphObject = response.getGraphObject();
         String s = textViewResults.getText().toString();
         if (graphObject != null) {
             JSONObject jsonObject = graphObject.getInnerJSONObject();
             try {
               JSONArray array = jsonObject.getJSONArray("data");
               for (int i = 0; i < array.length(); i++) {
                  JSONObject object = (JSONObject) array.get(i);
                  Log.d(TAG, "permalink = "+object.get("permalink"));
               }
             } 
             catch (JSONException e) {
                e.printStackTrace();
             }
         }
     }
});

requests.add(request1);

// Request-2   
String userQuery = "SELECT name FROM user WHERE uid=actor_id";

Bundle args2=new Bundle();
args2.putString("q", userQuery);

Request request2 = new Request(session, "fql", args2, HttpMethod.GET);

request2.setCallback(new com.facebook.Request.Callback() {
     @Override
     public void onCompleted(Response response) {
         GraphObject graphObject = response.getGraphObject();
         String s = textViewResults.getText().toString();
         if (graphObject != null) {
             JSONObject jsonObject = graphObject.getInnerJSONObject();
             try {
               JSONArray array = jsonObject.getJSONArray("data");
               for (int i = 0; i < array.length(); i++) {
                  JSONObject object = (JSONObject) array.get(i);
                  Log.d(TAG, "name = "+object.get("name"));
               }
             } 
             catch (JSONException e) {
                e.printStackTrace();
             }
         }
     }
});

requests.add(request2);

// Execute Batch
RequestBatch requestBatch=new RequestBatch(requests);
requestBatch.setTimeout(10000);

List<Response> responses = requestBatch.executeBatchAndWait();

Hope that helps. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top