2013-04-18 141 views
4

我想要獲取特定朋友的照片,我被加了標籤,並且我的照片也是這個朋友被標記的地方。我使用fql,這樣的地方, $ _POST [friend_id]先前是通過列出所有朋友的表單傳遞的:Facebook api PHP獲取朋友照片我標記的地方

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

我可以這樣做嗎?

感謝

回答

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