2

我正在尝试对 java 中的图形 API 使用批处理请求。实际上,它是一个 HTTPClient 正在发出图形 API 请求。

我试图构造一个这样的批处理请求数组:

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+"}]";

然后我对请求进行 URLEncode: String query = URLEncoder.encode(batch_request)

并将其传递给图形 API,如下所示: https://graph.facebook.com/?batch= "+query+"&access_token="+accessToken

我没有得到任何结果:(。它返回错误 500。

有什么想法吗?

4

1 回答 1

0

对于 fql 查询的批量请求,您可以这样做。我已经成功地尝试过了。

//$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 获取 thre 查询的整个结果的 json 数组。

来源:https ://stackoverflow.com/a/9635233/1045444

于 2012-06-26T06:32:02.730 回答