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;