Facebook FQL for Likes总是返回True

时间:2013-02-06 03:18:02

标签: php facebook facebook-fql

我试图查看已授予权限的用户是否喜欢指定的FB页面。问题是,即使页面没有被喜欢,它也总是返回true。这是代码:

public function verifyFbLike($userId, $objectId)
    {
        $appID = 'XXX';
        $clientSecret = 'XXX';
        $url = 'https://graph.facebook.com/oauth/access_token?client_id=' . $appID . '&client_secret=' . $clientSecret . '&grant_type=client_credentials';
        $accessToken = file_get_contents($url);
        $accessToken = str_replace('access_token=', '', $accessToken);

        $query = urlencode('SELECT user_id FROM like WHERE object_id="' . $objectId . '"');
        $xml = file_get_contents('https://api.facebook.com/method/fql.query?query=' . $query . '&access_token=' . $accessToken);
        $xmlObj = new SimpleXMLElement($xml);

        // See if user did like the object or not
        if($xmlObj->attributes()->list == 'true')
            return TRUE;
        else
            return FALSE;
}

1 个答案:

答案 0 :(得分:0)

将urlencode(...)更改为rawurlencode(...)修复它。