In graph api, Pages.isFan method not working, what s method for checking user fan of a page in graph api?
Thanks.
In graph api, Pages.isFan method not working, what s method for checking user fan of a page in graph api?
Thanks.
UPDATE 2:
To check if the current user is a fan of the Facebook page on landing at your tab check this answer.
UPDATE:
You can use the likes
connection to check if a user is a fan of a page:
https://graph.facebook.com/me/likes/PAGE_ID
&access_token=ACCESS_TOKEN
This would return either an empty data array:
Array
(
[data] => Array
(
)
)
Or if fan:
Array
(
[data] => Array
(
[0] => Array
(
[name] => Real Madrid C.F.
[category] => Professional sports team
[id] => 19034719952
[created_time] => 2011-05-03T20:53:26+0000
)
)
)
So this is how we check using the PHP-SDK:
<?php
require ../src/facebook.php ;
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
appId => APP_ID ,
secret => APP_SECRET ,
));
$user = $facebook->getUser();
if ($user) {
try {
$likes = $facebook->api("/me/likes/PAGE_ID");
if( !empty($likes[ data ]) )
echo "I like!";
else
echo "not a fan!";
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(array(
scope => user_likes
));
}
// rest of code here
?>
Similar script usingJS-SDK:
FB.api( /me/likes/PAGE_ID ,function(response) {
if( response.data ) {
if( !isEmpty(response.data) )
alert( You are a fan! );
else
alert( Not a fan! );
} else {
alert( ERROR! );
}
});
// function to check for an empty object
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
Code taken from my tutorial.
While pages.isFan
is still working for me, you can use the FQL page_fan
table with the new PHP-SDK:
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid FROM page_fan WHERE uid=$user_id AND page_id=$page_id"
));
if(!empty($result)) // array is not empty, so the user is a fan!
echo "$user_id is a fan!";
From the documentation:
To read the page_fan table you need:
- any valid
access_token
if it is public (visible to anyone on Facebook).user_likes
permissions if querying the current user.friends_likes
permissions if querying a user s friend.
Here s another approach that relies on the signed_request POST variable that Facebook sends to every tab app page (if you have the "OAuth 2.0 for Canvas" advanced option turned on.
The nice thing about this is you don t need to send another fql.query.
Or you can use fbml if you whant for example show some content if they are fan or made some dinamic stuff.
example:
<fb:fbml version="1.1">
<fb:visible-to-connection>This part is visible for fans only!
<fb:else>This part is visible for non-fans</fb:else>
</fb:visible-to-connection>
</fb:fbml>
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...