0

我在这里有这个代码,它允许我提取喜欢特定页面的朋友,但我需要提取不喜欢特定页面的朋友。

这是代码:

$users = $facebook->api(array('method' => 'fql.query',
        'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN(
    SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
        SELECT uid2 FROM friend WHERE uid1 = me()
    ))"));

我应该如何使用 OUTER JOIN 或 SMTH 得到这样的东西:

$users = $facebook->api(array('method' => 'fql.query',
            'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid NOT IN(
        SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
            SELECT uid2 FROM friend WHERE uid1 = me()
        ))"));
4

1 回答 1

0

看到它不支持 OUTER JOIN 或 NOT IN,请尝试这样做(不确定这是否是最好的方法,但应该可以)

$likes = $facebook->api(array('method' => 'fql.query',
    'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN(
SELECT uid FROM page_fan WHERE page_id='411133928921438' AND uid IN (
    SELECT uid2 FROM friend WHERE uid1 = me()
))"));

$allfriends = $facebook->api(array('method' => 'fql.query',
    'query' => "SELECT uid, first_name, pic_small FROM user WHERE uid IN (
    SELECT uid2 FROM friend WHERE uid1 = me()
)"));

// Loop through the rows
// I think there is a page where you can test FQL at developers.facebook.com, I'll see if I can find it on my phone so I can see what the JSON response looks like and fix this code, in the mean while see if this works

// Yeah so the code does this:
// Loop through each item in the $allfriends result, (put the contents of the row into the $friend variable
foreach( $allfriends as $friend )
{  
   // This bit I need to change, this is supposed to look in the $likes array to see if the UID is present, but it will be comparing the uid against the whole object - need to tweak this
   if( !in_array($friend['uid'], $likes) ) 
   {
       // Each friend that doesn't like the page should hit this part of the loop
       echo $friend['uid'];
   }                 
}

免责声明 - 我使用 PHP 已经有 5 年了,而且自从我接触 FQL 以来已经过了很长时间 - 让我知道是否有任何工作/不起作用(如果它起作用,我会感到惊讶:D)

于 2012-05-21T09:47:55.977 回答