簡體   English   中英

Facebook圖形api視頻拉

[英]facebook graph api video pulling

我正在嘗試在網站上嵌入一個Facebook視頻庫。

我的問題是,它只顯示一個視頻,而facebook圖顯示多個。 如何顯示所有視頻?

<?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'
}
?>

演示

移除后:

$ago_value = time_elapsed_string($converted_date_time);
該代碼循環播放所有視頻。

我也改變了這個:

$feed_item_count = count($obj['data']);
for ($x = 0; $x < 10; $x++)

為此:

$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM