facebook-graph-apifacebook-javascript-sdkjsonpathfacebook-batch-request

facebook batch request with jsonpath


With Facebook, i need to know, who (which user) has commented on a post on a facebook-page. I make two requests with facebook-batch-requests in my javascript-file, the first for all the posts and with the second, I want the requests of each post. Nice to have, if i can choose just the posts which have some comments.

FB.api('/', 'POST', {
  batch: [
  {
    // all posts from page from last year
    'method': 'GET',
    'name': 'posts_page_year',
    'omit_response_on_success': false,
    'relative_url': fbPageID + '/posts?since=2012-01-01&until=' + timeNow + '&limit=200000'
  },
  {
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id[?(@.comments.count!=0)]}"
  }
]
}, function(response) {
  callback(response);
}
);

My problem is the second batch-request, it returns an error (#803). I tried out a little bit.

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.0.id}"
}

returns an object with the first post-request. Everything is Good. But I want this of every Post, not just the first one.

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id}"
}

returns an error (#803) Some of the aliases you requested do not exist and a list of all ID's.

{
    // all post-ids from last year
    'method': 'GET',
    "relative_url": "/{result=posts_page_year:$.data.*.id[?(@.comments.count!=0)]}"
}

returns this error: (#803) Some of the aliases you requested do not exist: {result=posts_page_year:$.data.*.id[

I tried out nearly everything and need your help cause I don't know how to fix the problem. THX!


Solution

  • In the Facebook batch documentation, it states:

    Note that for security reasons filter and script JSONPath constructs are not allowed in the JSONPath expression.

    This probably means you can't use code like ?(@.comments.count!=0)