[英]facebook graph api video pulling
I'm trying to embed a facebook video gallery on a website. 我正在尝试在网站上嵌入一个Facebook视频库。
My problem is that it only shows one video, while the facebook graph shows multiple. 我的问题是,它只显示一个视频,而facebook图显示多个。 How can I make all the videos appear?
如何显示所有视频?
<?php
$json_link = "https://graph.facebook.com/sophia.deboer/videos?access_token=862683673820828|15Gx44NW43LHI92o__bRPA6lz44&fields=id,name,description,created_time,from,source&limit=10";
$json = file_get_contents($json_link);
$obj = json_decode($json, true);
$feed_item_count = count($obj['data']);
for ($x = 0; $x < 10; $x++) {
echo "<div class='item_box'>";
echo "<div style='overflow:hidden;'>";
// video source
$source = $obj['data'][$x]['source'];
echo "<div class='col-lg-6'>";
echo "<video src='{$source}' controls>";
echo "Your browser does not support the video tag.";
echo "</video>";
echo "</div>"; // end 'row'
echo "<div class='col-lg-6'>";
// user's custom message
$name = isset($obj['data'][$x]['name']) ? htmlspecialchars_decode($obj['data'][$x]['name']) : "Video #" . $obj['data'][$x]['id'];
$description = htmlspecialchars_decode(str_replace("\n", "<br>", $obj['data'][$x]['description']));
// when it was posted
$created_time = $obj['data'][$x]['created_time'];
$converted_date_time = date('Y-m-d H:i:s', strtotime($created_time));
$ago_value = time_elapsed_string($converted_date_time);
// from
$page_id = $obj['data'][$x]['from']['id'];
$page_name = $obj['data'][$x]['from']['name'];
echo "<h2 style='margin: 0 0 .5em 0;'>{$name}</h2>";
echo "<div>";
echo $description;
echo "</div>";
echo "<div style='margin:.5em 0 0 0; color: #999;'>";
echo "Posted {$ago_value} by <a href='https://facebook.com/{$page_id}' target='_blank'>{$page_name}</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<hr />";
echo "</div>"; // end 'item_box'
}
?>
After removing : 移除后:
$ago_value = time_elapsed_string($converted_date_time);
The code loops all videos. 该代码循环播放所有视频。
I also changed this: 我也改变了这个:
$feed_item_count = count($obj['data']);
for ($x = 0; $x < 10; $x++)
To This: 为此:
$feed_item_count = count($obj['data']);
for ($x = 0; $x < $feed_item_count; $x++)
<?php
$json_link = "https://graph.facebook.com/sophia.deboer/videos?access_token=862683673820828|15Gx44NW43LHI92o__bRPA6lz44&fields=id,name,description,created_time,from,source&limit=10";
$json = file_get_contents($json_link);
$obj = json_decode($json, true);
$feed_item_count = count($obj['data']);
for ($x = 0; $x < $feed_item_count; $x++) {
echo "<div class='item_box'>";
echo "<div style='overflow:hidden;'>";
// video source
$source = $obj['data'][$x]['source'];
echo "<div class='col-lg-6'>";
echo "<video src='{$source}' controls>";
echo "Your browser does not support the video tag.";
echo "</video>";
echo "</div>"; // end 'row'
echo "<div class='col-lg-6'>";
// user's custom message
$name = isset($obj['data'][$x]['name']) ? htmlspecialchars_decode($obj['data'][$x]['name']) : "Video #" . $obj['data'][$x]['id'];
$description = htmlspecialchars_decode(str_replace("\n", "<br>", $obj['data'][$x]['description']));
// when it was posted
$created_time = $obj['data'][$x]['created_time'];
$converted_date_time = date('Y-m-d H:i:s', strtotime($created_time));
//$ago_value = time_elapsed_string($converted_date_time);
// from
$page_id = $obj['data'][$x]['from']['id'];
$page_name = $obj['data'][$x]['from']['name'];
echo "<h2 style='margin: 0 0 .5em 0;'>{$name}</h2>";
echo "<div>";
echo $description;
echo "</div>";
echo "<div style='margin:.5em 0 0 0; color: #999;'>";
echo "Posted {$ago_value} by <a href='https://facebook.com/{$page_id}' target='_blank'>{$page_name}</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<hr />";
echo "</div>"; // end 'item_box'
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.