The following batch request for retrieve friends using the same app is not working:
var search = {batch: [
{
'name' : 'getFriends',
'relative_url': 'method/fql.query?query=SELECT+uid,+first_name,+name,+pic_square,+pic_small+FROM+user+WHERE+is_app_user=1+and+uid+IN+(SELECT+uid2+FROM+friend+WHERE+uid1=' + userId + ')'
},
{
'method': 'get',
'relative_url': '{result=getFriends:$.data[*].uid}/news.reads/article',
}
]};
and the following code executes the batch request:
FB.api('/', 'post', search, function(response) {
console.log(response);
});
but the first search returns null. What’s wrong with the query?
According to facebook documentation for batch requests, the *relative_url* is
(…) a relative_url (the portion of the URL after graph.facebook.com)
get from here.
So I changed the first block of code to:
var search = {batch: [
{
'name' : 'getFriends',
'method' : 'GET',
'relative_url': 'method/fql?q=SELECT uid, first_name, name, pic_square, pic_small FROM user WHERE is_app_user=1 and uid IN (SELECT uid2 FROM friend WHERE uid1=me())'
},
{
'method': 'GET',
'relative_url': '{result=getAmigos:$.data[*].uid}/news.reads/article'
}
]};
the relative_url of the first block on the batch works at Open Graph API Tool at facebook, but at the JS the http code is 500 and the message body is:
{
"error": {
"message": "Graph batch API does not allow REST API method fql",
"type": "FacebookApiException",
"code": 3
}
}
but in the api batch requests documentation allows fql queries. The documentation is outdated? Should I open a bug?
P.S: the fql without the batch request is
SELECT uid, first_name, name, pic_square, pic_small
FROM user WHERE is_app_user=1
and uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
it’s working now. I just add the
access_tokenparameter at the batch object. like this:the other trick was use the jsonpath expression in a different way. I couldn’t make the second request for each user of the first request. So I changed the way to get it adding the friends ids at the end of the graph api request. I think that my first thought about a request per friend it’s not possible using the batch request.
Then I did the call of the batch:
Now it’s just organize the posts retrieved.
[]’s