Facebook api php获取我标记的朋友照片

时间:2013-04-18 05:11:34

标签: php facebook api

我想获取我标记的特定朋友照片,以及我的照片,其中标记了同一位朋友。我正在使用fql,类似这样的地方,其中$ _POST [friend_id]先前已从表单传递列出了我所有的朋友:

$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));

我可以这样做吗?

由于

1 个答案:

答案 0 :(得分:2)

尝试以下查询:

要将您朋友的照片放到标记的位置:

$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())";

您朋友被贴上标签的照片:

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