小编enj*_*100的帖子

如何获取 YouTube 视频持续时间?

所以我想获取 YouTube 视频的持续时间。我找到了一些解决方案,但其中大多数已经过时了。我实际尝试过的:

public function getYTdata($url){
    $youtube = "http://www.youtube.com/oembed?url=". $url ."&format=json";

    $curl = curl_init($youtube);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $return = curl_exec($curl);
    curl_close($curl);
    return json_decode($return, true);
}
Run Code Online (Sandbox Code Playgroud)

输出:

{"thumbnail_url":"https:\/\/i.ytimg.com\/vi\/jmQsk6tm5aY\/hqdefault.jpg","provider_url":"https:\/\/www.youtube.com\/","thumbnail_height":360,"type":"video","provider_name":"YouTube","version":"1.0","html":"<iframe width=\"480\" height=\"270\" src=\"https:\/\/www.youtube.com\/embed\/jmQsk6tm5aY?feature=oembed\" frameborder=\"0\" gesture=\"media\" allow=\"encrypted-media\" allowfullscreen><\/iframe>","author_name":"Trap Nation","width":480,"title":"Evalyn - Filthy Rich (Sweater Beats Remix)","height":270,"thumbnail_width":480,"author_url":"https:\/\/www.youtube.com\/user\/AllTrapNation"}
Run Code Online (Sandbox Code Playgroud)

我的方法不显示持续时间。那么我怎样才能得到youtube视频的持续时间呢?

php laravel

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

laravel ×1

php ×1