php - What's method for checking user fan of a page in GRAPH API? -
in graph api, pages.isfan method not working, what's method checking user fan of page in graph api?
thanks.
update 2:
check if current user fan of facebook page on landing @ tab check answer.
update:
can use likes
connection check if user fan of page:
https://graph.facebook.com/me/likes/page_id &access_token=access_token
this return either 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 how check using php-sdk:
<?php require '../src/facebook.php'; // create our application instance (replace appid , 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 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 fan!'); else alert('not fan!'); } else { alert('error!'); } }); // function check empty object function isempty(obj) { for(var prop in obj) { if(obj.hasownproperty(prop)) return false; } return true; }
code taken tutorial.
while pages.isfan
still working me, can use fql page_fan
table new php-sdk:
$result = $facebook->api(array( "method" => "fql.query", "query" => "select uid page_fan uid=$user_id , page_id=$page_id" )); if(!empty($result)) // array not empty, user fan! echo "$user_id fan!";
from documentation:
to read page_fan table need:
- any valid
access_token
if public (visible on facebook).user_likes
permissions if querying current user.friends_likes
permissions if querying user's friend.
Comments
Post a Comment