dongmouhao7438 2017-12-28 13:52
浏览 178
已采纳

如何使用php和API从url获取youtube视频的缩略图

Below code, I got title and description but I want image as well as how to get the main image of video from JSON data.

$videoid = 'cMC_PtgKDJE';
$apikey = 'xyzxyzxyz';  //My API key

$json = file_get_contents('https://www.googleapis.com/youtube/v3/videos?id='.$videoid.'&key='.$apikey.'&part=snippet');
$ytdata = json_decode($json);
print_r($ytdata);
echo '<h1>Title: ' . $ytdata->items[0]->snippet->title . '</h1>';
echo 'Description: ' . $ytdata->items[0]->snippet->description;
  • 写回答

2条回答 默认 最新

  • doupiao1893 2017-12-28 13:55
    关注

    Each YouTube video has 4 generated images.You can create the url as fallows

    https://img.youtube.com/vi/<video-id-here>/0.jpg
    

    DEMO

    If you want high quality image then you can read following atricle

    how to get a youtube video’s thumbnail image in high quality

    How to get video id from youtube url

    $url = "http://www.youtube.com/watch?v=7zWKm-LZWm4&feature=relate";
    parse_str( parse_url( $url, PHP_URL_QUERY ), $url_vars );
    echo $url_vars['v'];    
      // Output: 7zWKm-LZWm4
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 利用单片机产生正弦信号,来测量差分放大电路放大倍数和共模放大倍数的思路和仿真
  • ¥66 定制开发肯德基自动化网站下单软件
  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题