cpilko
cpilko

Reputation: 11852

Retrieve Curated set of Photos from a Page stream

I'm working on an awareness campaign for a nonprofit. We're asking people to upload photos of them holding a sign to the nonprofit's Facebook page. Since they don't show clearly on the timeline, we want to scrape these photos and display them on a page on the nonprofit's website.

Getting all the photos is easy. I'm using the following FQL to get them:

SELECT post_id, actor_id, message, attachment, place, created_time 
  FROM stream WHERE source_id = PAGE_ID and source_id <> actor_id 
      AND attachment.media <> '' AND created_time > 1338834720 
  LIMIT 50

The problem is, there are other photos that people are uploading to the website that we don't want featured in this gallery. What I'd like to do is further filter this result set so we only get photos the page or a page admin has liked or commented on. This is where I'm getting stuck.

When I convert this to a multi-query and feed the results of the query above into:

SELECT post_id FROM like WHERE user_id = PAGE_ID AND post_id IN (SELECT post_id FROM #query1)

I get an OAuth error that I can only query like for the logged in user. This happens even when authenticating as the app using the PHP SDK.

I've tried getting people to add a text string to their message when they post, but that's not happening. Some people are adding that string to photos the nonprofit doesn't want and the best photos in the nonprofit's eyes don't have that string in them.

Thanks for your help.

Upvotes: 0

Views: 288

Answers (2)

C3roe
C3roe

Reputation: 96417

Try doing your queries as Batch Requests. You can „name” queries in there to reference their results in other queries, and you can specify different access tokens for each individual operation.

Upvotes: 0

cpilko
cpilko

Reputation: 11852

Ok, answered my own question.

I'm using this FQL multiquery via the PHP SDK to get the curated group of photos. I settled on a comment made my any page admin:

  {
  'activity': 
     "SELECT post_id FROM stream WHERE source_id = PAGE_ID 
      AND attachment.fb_object_type = 'photo' AND created_time > 1338834720 
      AND comments.count > 0 LIMIT 100",
  'commented':
     "SELECT post_id, text, fromid FROM comment 
      WHERE post_id IN (SELECT post_id FROM #activity) 
      AND fromid IN (SELECT uid FROM page_admin WHERE page_id = PAGE_ID)", 
   'accepted':
      "SELECT post_id, actor_id, message, attachment, place, created_time, likes 
       FROM stream WHERE post_id IN (SELECT post_id FROM #commented) 
       ORDER BY likes.count", 
    'images': 
      "SELECT pid, src, src_big, src_small, src_width, src_height FROM photo 
       WHERE pid IN (SELECT attachment.media.photo.pid FROM #accepted)",
    'users':
       "SELECT name, uid, current_location, locale FROM user 
        WHERE uid IN (SELECT actor_id FROM #accepted)",
     'pages':
       "SELECT name, page_id FROM page 
        WHERE page_id IN (SELECT actor_id FROM #accepted)",
     'places': 
       "SELECT name, page_id, description, display_subtext, latitude, longitude 
        FROM place WHERE page_id IN (SELECT place FROM #accepted)"
     }

The live site is here: http://getwellgabby.org/show-us-a-sign. Lots of PHP on the back end to combine the results and using ThickBox for the photo display.

Upvotes: 1

Related Questions