dongtiao0657 2018-12-10 13:14
浏览 42

Facebook与图形API分页

I'm kinda new using graph API.I made on my localhost server to import just videos from one facebook page to an website on localhost.

I made a limit for 9 videos on one page but I couldn't get the part with pagination with buttons next and previous.

I watched the documentation and it is pretty complicated "I don't understand it".One time I made "next" button but it shows me pure json not video embeded like on the first page.

    require_once 'vendor/facebook/graph-sdk/src/Facebook/autoload.php';

$fb = new \Facebook\Facebook([
    'app_id' => '2062191324084844',
    'app_secret' => 'app-secret',
    'default_graph_version' => 'v3.2',

]);

try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/400880516961734/videos?limit=9',
    'acces-token'
  );

} 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;
}
$graphEdge = $response->getGraphEdge();
/* handle the result */
        ?><div class="row">
        <?php
        foreach ($graphEdge as $graphNode) {
            $id = $graphNode->getField('id');
            echo '
                <div class="col-md-4 mt-2 mb-2">
                <div class="fb-video" data-href="https://www.facebook.com/facebook/videos/'.$id.'/" data-width="500" data-height="300" data-allowfullscreen="true"></div>
                </div>
                ';
        } ?>
        </div>
<?php

    $graphEdge = $response->getGraphEdge();

// Get the next page of results
$nextPageOfVideos = $fb->next($graphEdge);
// Or the previous page of results
$previousPageOfVideos = $fb->previous($graphEdge);

echo $nextPageOfVideos;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 PADS Logic 原理图
    • ¥15 PADS Logic 图标
    • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
    • ¥20 气象站点数据求取中~
    • ¥15 如何获取APP内弹出的网址链接
    • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
    • ¥50 STM32单片机传感器读取错误
    • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
    • ¥15 机器人轨迹规划相关问题
    • ¥15 word样式右侧翻页键消失