列出播放列表项时返回的持续时间?

Joh*_*ith 11 youtube youtube-api youtube-data-api

我正在使用这个网址:

https://www.googleapis.com/youtube/v3/playlistItems?
    playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
    part=snippet,contentDetails,status
Run Code Online (Sandbox Code Playgroud)

获取YouTube播放列表项目.

我包括了part我感兴趣的所有内容,但我发现无法退回duration该项目.

https://developers.google.com/youtube/v3/docs/playlistItems/list

这可能吗?

目前我只回来了这样的项目:

{
  "status": {
    "privacyStatus": "public"
  }, 
  "kind": "youtube#playlistItem", 
  "contentDetails": {
    "videoId": "tL-Ba86UhoE"
  }, 
  "snippet": {
    "playlistId": "FLFe0SGeFqZ9E2owO5ZDZpwg", 
    "thumbnails": {
      "default": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/default.jpg", 
        "width": 120, 
        "height": 90
      }, 
      "high": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/hqdefault.jpg", 
        "width": 480, 
        "height": 360
      }, 
      "medium": {
        "url": "https://i1.ytimg.com/vi/tL-BA86Uhoh/mqdefault.jpg", 
        "width": 320, 
        "height": 180
      }
    }, 
    "title": "Music Video", 
    "resourceId": {
      "kind": "youtube#video", 
      "videoId": "tL-BA86Uhoh"
    }, 
    "channelId": "UCFe0SGNFqZ9E2owO5ZDZpwg", 
    "publishedAt": "2013-07-06T18:41:43.000Z", 
    "channelTitle": "channeltitle", 
    "position": 0, 
    "description": "Video for"
  }, 
  "etag": "\"ePFRUfYBkeQ2ncpP9OLHvB0fDw4/CJiCG6tvFw4quQlzJq3gTrhvCNo\"", 
  "id": "FL-fX6VqgtTfCJWKNE4aVRODKSrRgEdGvw"
}, 
Run Code Online (Sandbox Code Playgroud)

完全没有时间指示.我宁愿避免因为要求返回单个视频的持续时间而淹没YouTube.

Yah*_*hia 0

使用此功能:[仅与 Youtube Api v3 一起使用]

浏览器:

您必须使用以下命令发出另一个 http 请求:

https://www.googleapis.com/youtube/v3/videos?id= {视频 id}&part=contentDetails&key={api 密钥}

等等

内容详情

你会发现持续时间

PHP:

function getDuration($apiKey,$video_id){        
    $link='https://www.googleapis.com/youtube/v3/videos?id='.$video_id.'&part=contentDetails&key='.$apiKey;
    $data = json_decode(file_get_contents($link),true);
    $duration =  $data['items'][0]['contentDetails']['duration'];   
    return $duration;
 }
Run Code Online (Sandbox Code Playgroud)