Detecting if user like facebook app
I'm trying for hours now to check if the current user is "liked" my app. I do require "user_likes" permission on login but even when I'm clicking the like button, when I check if the user like the app with isFan or with FQL I still get zero likes!
this is how I'm trying to get if the user "liked" the app:
$isFan = $facebook->api(array(
"method" => "pages.isFan",
"page_id" => xxxxx,
"uid" => $session
));
if($isFan === TRUE)
echo "I'm a fan!";
OR
$likes = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT uid FROM page_fan WHERE page_id='xxxxx' AND uid='$session'",
));
print 'likes found: ' . count($likes) . '<br />';
both method开发者_如何学运维s gives me nothing, please if some one can help me it will be great!
Thanks! Moti
You want to use the Page ID instead of the App ID. I'm not sure if your page is a Facebook Page (facebook.com/pages/ [PAGE_NAME] / [PAGE_ID] ) or if you have a non-Facebook page.
Obviously if you have a Facebook page then the number on the end of the URL will be your Page ID. Otherwise if you have a non-Facebook page you can use the graph to get your Page ID.
https://graph.facebook.com/?id= [PAGE_URL]
Use that ID instead of the app ID and it should give you the correct result. To be sure try it out with the tool on the Facebook docs
Is your page public? From the link posted in the comments by squinlan:
If the user's pages are set to less than everyone privacy, you must ask the user for the user_likes extended permission and include a valid user access token in the API call.
So when you go though the authorisation process as documented here, you will finally be issued with an access token. You then append that to any requests you make to ensure the correct permission is granted:
$isFan = $facebook->api(array(
"method" => "pages.isFan",
"page_id" => xxxxx,
"uid" => $session,
"access_token" => $access_token
));
精彩评论