Facebook api php - 检查用户是否喜欢该页面

时间:2015-12-23 12:05:03

标签: php facebook facebook-like

尝试用php检查用户是否喜欢facebook。检查过类似的问题,他们似乎已经过时了。该应用程序具有user_likes的权限。使用javascript进行登录。在php / js中尝试两种解决方案都返回空结果。

$fb = new Facebook\Facebook([
    'app_id' => '000',
    'app_secret' => '000',
    'default_graph_version' => 'v2.4',
]);

$helper = $fb->getJavaScriptHelper();

try {
    $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

$response = $fb->get('/me/likes/40796308305', $accessToken);

if ( $_GET['debug']=='1' ) {    
    echo("<pre>");
    print_r($response);
    echo("</pre>");
}

我得到的回答如下:

Facebook\FacebookResponse Object
(
    [httpStatusCode:protected] => 200
    [headers:protected] => Array
        (
            [Access-Control-Allow-Origin] => *
            [Content-Type] => application/json; charset=UTF-8
            [X-FB-Trace-ID] => AJjNMCquJMO
            [X-FB-Rev] => 2105600
            [ETag] => "1050253aec7b29caff644806927dabfa81406eee"
            [Pragma] => no-cache
            [Cache-Control] => private, no-cache, no-store, must-revalidate
            [Facebook-API-Version] => v2.4
            [Expires] => Sat, 01 Jan 2000 00:00:00 GMT
            [Vary] => Accept-Encoding
            [X-FB-Debug] => 6+GDFRqzzKDCdxTWVr9KKZ3Bbo57jGhTvmTHFmtarBr8AoQKY/5ymi4yXp1Kzb3zVYcs+AJKP2czljJvggCF6Q==
            [Date] => Wed, 23 Dec 2015 11:53:40 GMT
            [Connection] => keep-alive
            [Content-Length] => 11
        )

    [body:protected] => {"data":[]}
    [decodedBody:protected] => Array
        (
            [data] => Array
                (
                )

        )

    [request:protected] => Facebook\FacebookRequest Object
        (
            [app:protected] => Facebook\FacebookApp Object
                (
                    [id:protected] => 889383307815047
                    [secret:protected] => 0892e37a317e97748bab6f64ad984b6e
                )

            [accessToken:protected] => CAAMo47AhqIcBAD9wcLEXslcyGW1wYLidu1GNmlSok2ZAgdZAU3IOjSKBhplSgFz8c8ZBGoyRGVHZB4qC1vwOeNozSV8M5WcgipyfPxy7RimPaZBhDgDnzG692BLj7dDZBgeZB4h7sgNr4kcjAnD4VzQE6wGZCZBpfijZBdZBfuCAww9ZCvxESMwJGRQZCeFSHKw8DORQ7m6mPPc2UjLq2TdqESZAZCv
            [method:protected] => GET
            [endpoint:protected] => /me/likes/40796308305
            [headers:protected] => Array
                (
                    [Content-Type] => application/x-www-form-urlencoded
                )

            [params:protected] => Array
                (
                )

            [files:protected] => Array
                (
                )

            [eTag:protected] => 
            [graphVersion:protected] => v2.4
        )

    [thrownException:protected] => 
)

0 个答案:

没有答案