如何用java实现facebook批量fql

如何用java实现facebook批量fql,java,facebook,batch-file,facebook-fql,Java,Facebook,Batch File,Facebook Fql,在facebook fql中有以下代码 https://developers.facebook.com/docs/reference/api/batch/ curl \ -F 'access_token=…' \ -F 'batch=[ \ {"method": "GET", "relative_url": "me"}, \ {"method": "GET", "relative_url": "me/friends?limit=

在facebook fql中有以下代码

https://developers.facebook.com/docs/reference/api/batch/


curl \
    -F 'access_token=…' \
    -F 'batch=[ \
            {"method": "GET", "relative_url": "me"}, \
            {"method": "GET", "relative_url": "me/friends?limit=50"} \
        ]'\
    https://graph.facebook.com
它应该与json一起发送 但我真的不明白怎么做 有什么帮助吗


谢谢

我相信您的问题是如何使用Facebook Graph API执行批处理请求。为此,您必须向发出POST请求

"https://graph.facebook.com" 
并且要发送的post数据应该是

"batch=[{'method': 'GET', 'relative_url': 'me'}, {'method': 'GET', 'relative_url': 'me/friends?limit=50'}]&access_token=@accesstoken" 
在您的情况下,[@accesstoken必须替换为您的访问令牌值]

此请求将返回访问令牌所有者的详细信息(通常是当前登录的用户)和50个facebook好友的列表包含用户的id和姓名字段以及页面标题可以省略

我不确定你指的是java还是Javascript。请具体说明

我基本上是一个C程序员。在这里,将为您提供一个用C执行上述请求的代码

WebRequest webRequest = WebRequest.Create("https://graph.facebook.com");
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-UrlEncoded";
byte[] buffer = Encoding.UTF8.GetBytes("batch=[{'method': 'GET', 'relative_url': 'me'}, {'method': 'GET', 'relative_url': 'me/friends?limit=50'}]&access_token=@ACCESSTOKEN");
webRequest.ContentLength = buffer.Length;
using (Stream stream = webRequest.GetRequestStream())
{
    stream.Write(buffer, 0, buffer.Length);
    using (WebResponse webResponse = webRequest.GetResponse())
    {
        if (webResponse != null)
        {
            using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
            {
                string data = streamReader.ReadToEnd();
            }
        }
    }
}

这里变量数据将包含结果。

Salah,这里是我用作参考的示例,很抱歉,我不记得在哪里找到的

FB.api("/", "POST", {
    access_token:"MY_APPLICATION_ACCESS_TOKEN",
    batch:[
        {
            "method":"GET",
            "name":"get-photos",
            "omit_response_on_success": true,
            "relative_url":"MY_ALBUM_ID/photos"
        },
        {
            "method": "GET",
            "depends_on":"get-photos",
            "relative_url":"{result=get-photos:$.data[0].id}/likes"
        }
    ]
}, function(response) {
    if (!response || response.error) {
        console.log(response.error_description);
    } else {    
        /* Iterate through each Response */
        for(var i=0,l=response.length; i<l; i++) {
            /*  If we have set 'omit_response_on_success' to true in the Request, the Response value will be null, so continue to the next iteration */
            if(response[i] === null) continue;
            /*  Else we are expecting a Response Body Object in JSON, so decode this */
            var responseBody = JSON.parse(response[i].body);
            /*  If the Response Body includes an Error Object, handle the Error */
            if(responseBody.error) {
                // do something useful here
                console.log(responseBody.error.message);
            } 
            /*  Else handle the data Object */
            else {
                // do something useful here
                console.log(responseBody.data);
            }
        }
    }
});
你可以简单地使用api它非常强大和简单,你不必处理所有这些东西,它使用fql 例如,让你所有的朋友

Later<ArrayNode> friendsArrayList = this.Batcher.query("SELECT uid FROM user WHERE uid  IN (SELECT uid2 FROM friend WHERE uid1 = me())");
    for (JsonNode friend : friendsArrayList.get()) {
            .......
        }

它是成批的

你能更准确地回答你的问题吗?你尝试了什么,你期望什么,你得到了什么结果?你试过上面的命令吗?失败了吗?你有卷发器吗?它有反应吗?你得到了什么?您看到了什么错误消息?