最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论