如何从Facebook JS SDK获得类似状态

时间:2011-08-11 16:16:40

标签: facebook

我想知道是否可以使用FB JS SDK在我的Facebook应用程序( iframe )中获取like status

我想要的是以下但是在JS中。

<?php require 'lib/facebook.php';

$facebook = new Facebook( array( 
  'appId'   => APP_ID,
  'secret'  => APP_SECRET,
  'cookie'  => true
) );

try {
  $me = $facebook->api('/me');
} catch ( FacebookApiException $e ) {
  error_log( $e );
}

$signed_request = $facebook->getSignedRequest();
$liked = $signed_request['page']['liked'];

?>

<?php
if ( $liked ) : ?>
  YOU LIKE US!
<?php else : ?>
  YOU DON'T LIKE US YET!
<?php endif; ?>

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>

1 个答案:

答案 0 :(得分:3)

var session = FB.getSession();
FB.api(
    {
        method: 'fql.query',
        query: 'SELECT uid, page_id FROM page_fan WHERE uid=' + session.uid + ' AND page_id=YOUR_APP_ID'
    },
    function(response) {
        if(response instanceof Array && response.length > 0)
            alert("YOU LIKE US!");
        else
            alert("YOU DON'T LIKE US YET!");
    }
);