带有SQL批处理请求的Facebook Graph API

时间:2012-05-01 01:25:32

标签: facebook-graph-api facebook-fql facebook-batch-request

我正在尝试对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+"}]";

然后我URLncode请求:字符串查询= URLEncoder.encode(batch_request)

并将其传递给图形API,如下所示: https://graph.facebook.com/?batch= “+查询+” &安培;的access_token =“+的accessToken

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

有什么想法吗?

1 个答案:

答案 0 :(得分: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