Facebook /me/likes/[PAGE_ID] is broken


  • tutorials
  • (Updated at )

Facebook "likes" is still broken

Since Facebook Javascript SDK is not reliable, we use PHP SDK for most of the work, but unfortunately one of our most used check still have some problem, that is the so called isFan check.

I have the problem awhile ago and found no answer, and I have the same issue recently, and still found out it is not resolved.

Let's say, we have a Facebook object and the page id we need to check if a user is fan or not.

$facebook = new Facebook(array(  
    'appId'  => FACEBOOK_APP_ID,  
    'secret' => FACEBOOK_APP_SECRET,  
));  
$fanpage_id = '123456789';  

Using api() call

Normally you will do this and most of the time it will work.

$likes = $facebook->api("/me/likes/{$fanpage_id}");  
var_dump($likes);  

Sometimes you may get a empyt result, but if we just make /me/likes call to get a bunch of records, then we can find the page is already there.

$likes = $facebook->api("/me/likes");  
foreach ($likes['data'] as $data) {  
    if ($data['id'] === $fanpage_id) {  
        var_dump($data);  
        break;  
    }  
}  

Problem solved? NO, what if the user has 5K likes? Then we will have to do an infiniy loops.

Using FQL query

The last method and also suggestion from Facebook developer is using fql and query page_fan table directly.

fblike-bug.png

$fql = "SELECT created_time,type,uid,page_id FROM page_fan WHERE uid = me() AND page_id = {$fanpage_id}";  
$likes = $facebook->api(array(  
    'method' => 'fql.query',  
    'query' => $fql,  
));  
var_dump($likes);  

No, still nothing. And as expect grab all likes data and check by ourselves, then it's there.

$fql = "SELECT created_time,type,uid,page_id FROM page_fan WHERE uid = me()";  
$likes = $facebook->api(array(  
    'method' => 'fql.query',  
    'query' => $fql,  
));  
foreach ($likes as $data) {  
    if ($data['page_id'] === $fanpage_id) {  
        var_dump($data);  
        $liked = true;  
        break;  
    }  
}  

Conclusion

Seems Facebook will not fix the issue any sooner.

If you don't mind the slow like hell FQL, then it's somehow the better way, but reading from other threads, some people still get nothing from fql.

Do a few times "/me/likes?limit=" to get records and cross your finger.

Unlike and re-like may work form somebody, it doesn't work for me.

Reference

Ethan Liu avatar
Ethan Liu
A web developer, iOS developer, designer and a cat slave.

comments powered by Disqus