Filtering results from edge /[pageId]/posts

59 Views Asked by At

I would like to show the latest N Facebook posts on my website.

I am using this simple code:

var FB = require('fb')

FB.api('/flourandfire/posts', 'get', { fields: [ 'message', 'picture' ], access_token: '1694494XXXXXXXX|1ba36298123bbf9689942fXXXXXXXXXX' }, 
function (res) {
  if (!res || res.error) {
    console.log(!res ? 'error occurred' : res.error)
    return
  }
  console.log(res)
})

However, I need to be able to have some kind of filtering, since there is "noise" in the feed due to the direct link with Instagram (which results in short posts with a picture, that I do NOT want to include in the website's feed)

I basically need to somehow "differentiate" specific posts, which will then placed on the site.

I could fetch 100 posts and filter myself based on a specific tag (like #pub; however, there is the risk of having lots of Instagram posts, more than 100, and end up with ZERO posts on the website.

How would you solve this issue?

1

There are 1 best solutions below

2
On BEST ANSWER

There is no official filtering, i would do it like this:

  1. Get N entries by setting the limit parameter to N
  2. Filter them on your own
  3. If there are less than N elements after filtering, use another API call to get more items
  4. Repeat from Number 2

Just an idea though, you could also increase the initial limit - but it would usually result in a slower API call so be careful with that.