Question

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!

Was it helpful?

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)

OTHER TIPS

FB.api('/', 'POST', {
  batch: [
    {
      // 0: all likes from user
      'method': 'GET',
      'relative_url': 'me/likes'
    },
    {
      // 1: all user-posts from last month
      'method': 'GET',
      'relative_url': 'me/posts?since=' + timeMonthAgo + '&until=' + timeNow + '&limit=200000'
    },
    {
      // 2: all user-posts from last year
      'method': 'GET',
      'relative_url': 'me/posts?since=' + timeYearAgo + '&until=' + timeNow + '&limit=200000'
    }
  ]
  }, function (response) {
    callback(response);
  }
);

I had to set a Limit, so that each response has now a limit of content. It is possible to set the limit to an impossible large number. You have to set a time-range too with the since and until parameters.

I hope this helps somebody.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top