victor
victor

Reputation: 87

Facebook api php get friend photos where I'm tagged

I want to get specific friend photos that I'm tagged in, and my photos where this same friend is tagged in. I'm using fql, something like this, where $_POST[friend_id] is previously passed from a form with all my friends listed:

$facebook_login = "0";
$user = $facebook->getUser();
$perms = array('scope' => 'email,user_photos,read_mailbox');

if ($user) {
  try {
    $user_profile = $facebook->api('/me');
$facebook_login = "1";
  } catch (FacebookApiException $e) {
    $user = null;
  }

} else {
    die('<script>top.location.href="'.$facebook->getLoginUrl($perms).'";</script>');
}



//friend photos that I'm tagged in
$query = "SELECT id FROM photo WHERE from = $_POST[friend_id] AND tags IN ($user)";
$result = $facebook->api(array(
  'method' => 'fql.query',
  'query' => $query,
));

echo sprintf('<pre>%s</pre>', print_r($result,TRUE));


//my photos with my friend tagged in
$query = "SELECT id FROM photo WHERE from = $user AND tags IN ($_POST[friend_id])";
$result = $facebook->api(array(
  'method' => 'fql.query',
  'query' => $query,
));

echo sprintf('<pre>%s</pre>', print_r($result,TRUE));

Can I do this?

Thanks

Upvotes: 4

Views: 1228

Answers (1)

biggusjimmus
biggusjimmus

Reputation: 2776

Try the following queries:

To get your friend's photos where you're tagged:

$friend_id = $_POST['friend_id'];
$query = "SELECT object_id 
          FROM photo 
          WHERE owner=$friend_id AND 
                object_id IN (SELECT object_id FROM photo_tag WHERE subject=me())";

Your photos where your friend is tagged:

$query = "SELECT object_id 
          FROM photo 
          WHERE owner=me() AND 
                object_id IN (SELECT object_id FROM photo_tag WHERE subject=$friend_id)";

Upvotes: 2

Related Questions