问题
I want to check whether the loggedIn user has liked a specified page or not. Below is my code.
$fql_pageid = "SELECT url,site,id FROM object_url WHERE url
IN('http://developers.facebook.com/')";
$api_pageid = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql_pageid
));
$pageid = $api_pageid[0]["id"]; //get id of the specified page
$fql_like = 'SELECT object_id FROM like WHERE user_id=me()';
$api_like = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql_like
));
When I do var_dump($api_like)
, there are only 6 records appearing. But I checked my Facebook account, there are 22 likes.
Anyone knows what's wrong the above code? Or is there any other way to check whether a user has liked a specified page?
回答1:
Let's say that you want to check if the current user (uid=me()) is Fan of the "Big Bang Theory" page with *page_id=22934684677* (http://graph.facebook.com/TheBigBangTheory) you should run this query:
SELECT page_id FROM page_fan WHERE uid=me() AND page_id=22934684677
回答2:
If instead you want to see if the current user likes a website:
SELECT user_id FROM url_like WHERE url='http://someurl.com' AND user_id=me()
This is useful for page tab apps where normal like buttons will only like the page the tab resides in.
来源:https://stackoverflow.com/questions/9012205/check-if-a-facebook-user-likes-a-page-using-fql