dongquan8753 2016-04-05 13:07
浏览 135
已采纳

获取Facebook页面评论和评级

I have created a facebook app and approved the app to access manage_pages.I am looking for php code to get page access from page to get the page information.

For getting reviews and rating I am using the below code

require 'facebook-php-sdk-master/src/facebook.php';



$config = array();
$config['appId'] = '1489047331XXXXX';
$config['secret'] = '6ac210360aad27ab1044e4201XXXX';

$facebook = new Facebook($config);

print_r($facebook);

try {
    // 466400200079875 is Facebook id of Fan page https://www.facebook.com/pontikis.net
    $ret = $facebook->api("/page_id/ratings?field=open_graph_story", 'GET');
    print_r($ret);
} catch(Exception $e) {
    echo $e->getMessage();
}

I am getting the below error

(#210) This call requires a Page access token.

Any help will be highly appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • dsgrs26202 2016-04-16 05:46
    关注

    Create new object like this and set access_token if not exists:

            $fb = new Facebook([
            'app_id' => FB_APP_ID,
            'app_secret' => FB_APP_SECRET,
            'default_graph_version' => 'v2.5',
            'default_access_token' => isset($_SESSION['facebook_access_token']) ?
                $_SESSION['facebook_access_token'] : FB_APP_ID . '|'. FB_APP_SECRET
        ]);
    

    Change FB_APP_ID and FB_APP_SECRET, only with yours. Now you have access token, after that you can make requests and get data that u need access token for it like this (for the example):

        $request = $fb->request('GET', '/'.$page_id.'/');
        // Send the request to Graph
        try {
            $response = $fb->getClient()->sendRequest($request);
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            // When Graph returns an error
            echo 'Graph returned an error: ' . $e->getMessage();
            exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            // When validation fails or other local issues
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
        }
    
        $graphNode = $response->getGraphPage();
    
        var_dump($graphNode->all());
    

    Where $page_id is id of some page, where you can find it with its FB page URL .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题