php - Facebook: Check if User liked Facebook Fanpage Tab - Stack Overflow

I know, that my question was asked a lot of times here, but for me no answer worked. I've created

I know, that my question was asked a lot of times here, but for me no answer worked. I've created a Facebook Fanpage Tab. All the files are stored at my private Webspace. Now I want to determine if a user already liked the page or haven't liked it yet!

So I used this code:

<?php
    function parsePageSignedRequest() {
        if (isset($_REQUEST['signed_request'])) {
            $encoded_sig = null;
            $payload = null;
            list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
            $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
            $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
            return $data;
        }
        return false;
    }

    if($signed_request == parsePageSignedRequest()) {
        if($signed_request->page->liked) {
            $isteinfan = "false";
        } 
        else {
            $isteinfan = "true";

        }
    }   
    //PHP Variable an JavaScript übergeben
    echo "<script>";
    echo "isteinfan = '$isteinfan';";
    echo "console.log('ist ein fan: ');";
    echo "console.log(isteinfan);";
    echo "</script>";
?>

But it doesn't work. Can u give me help, please!!! Yours, Raphael

I know, that my question was asked a lot of times here, but for me no answer worked. I've created a Facebook Fanpage Tab. All the files are stored at my private Webspace. Now I want to determine if a user already liked the page or haven't liked it yet!

So I used this code:

<?php
    function parsePageSignedRequest() {
        if (isset($_REQUEST['signed_request'])) {
            $encoded_sig = null;
            $payload = null;
            list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
            $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
            $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
            return $data;
        }
        return false;
    }

    if($signed_request == parsePageSignedRequest()) {
        if($signed_request->page->liked) {
            $isteinfan = "false";
        } 
        else {
            $isteinfan = "true";

        }
    }   
    //PHP Variable an JavaScript übergeben
    echo "<script>";
    echo "isteinfan = '$isteinfan';";
    echo "console.log('ist ein fan: ');";
    echo "console.log(isteinfan);";
    echo "</script>";
?>

But it doesn't work. Can u give me help, please!!! Yours, Raphael

Share Improve this question asked Nov 21, 2011 at 18:10 RaphaelRaphael 5621 gold badge6 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I would remend you include the facebook php library, which you can download from https://github./facebook/php-sdk/tree/master/src. You have to place all the three files in the same directory. Then you can get the liked status very easily:

define('APP_ID','xxxxxxxx');
define('APP_SECRET','xxxxxxxx');

require ("facebook.php");

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

$signed_request = $facebook->getSignedRequest();

$liked = $signed_request["page"]["liked"];

Now $liked is a boolean which can be true or false

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744620051a4584288.html

相关推荐

  • php - Facebook: Check if User liked Facebook Fanpage Tab - Stack Overflow

    I know, that my question was asked a lot of times here, but for me no answer worked. I've created

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>