2

I am trying to use batch request against graph API in java. Actually it's an HTTPClient that is making a graph API request.

I tried to construct an array of batch request like this:

String query2 = "SELECT --- from tableX";

    String query = "SELECT --- from tableY";

    String batch_request= "[{\"method\":\"GET\",\"relative_url\":method/fql.query?query="+query+"},"+
    "{\"method\":\"GET\",\"relative_url\":method/fql.query?query="+query2+"}]";

Then I URLEncode the request: String query = URLEncoder.encode(batch_request)

And pass it to graph API like this: https://graph.facebook.com/?batch="+query+"&access_token="+accessToken

I am not getting any results :(. It returns error 500.

Any thoughts?

Sam
  • 21
  • 2

1 Answers1

0

For batch request of fql queries, you can do this. I have tried it successfully.

//$current_user=facebook id

 $query1="SELECT uid, name FROM user WHERE is_app_user=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user)";
 $query2="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user )";
 $query3="SELECT uid, name, work, education FROM user WHERE uid = $current_user";
 $queries = array(
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query1)),
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query2)),
           array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query3))
            );

            $objs = $facebook->api('/?batch='.json_encode($queries), 'POST');

$objs gets json array of whole result of thre queries.

Source: https://stackoverflow.com/a/9635233/1045444

Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226