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 .

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度