我使用这个url:
https://www.googleapis.com/youtube/v3/playlistItems?
playlistId=FLFe0SGNFqZ9E2owO5ZDZpeg&
part=snippet,contentDetails,status
获取YouTube播放列表。
我包含了所有我感兴趣的part
,但是我没有办法返回项目的duration
。
这可能吗?
目前我只得到这样一个项目:
{
"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"
},
完全没有时间指示。我宁愿避免在YouTube上充斥返回单个视频持续时间的请求。
使用这样的链接来获取许多视频的持续时间:
https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=idFirst,idSecond&key=YOUR_API_KEY
使用此函数:[仅用于Youtube Api v3]
浏览器:你必须发出另一个HTTP请求使用:
https://www.googleapis.com/youtube/v3/videos?id={video id}∂contentDetails&key={api key}
and on
contentDetails
你会发现持续时间
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;
}