如何从Youtube频道获取所有视频ID?
我如何从YouTube数据Feed获取所有视频ID?
我通过以下(API)网址收到youtube Feed:http://gdata.youtube.com/feeds/base/users/#userid#/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile
我已经知道如何从频道中提取链接,描述和缩略图,但我想从频道中提取所有视频ID(例如,http://www.youtube.com/watch? v = WWooNnPnHTs )
这是我的方式。 慢,但它的作品。 :)
function getVideos($channel){
if($channel == ""){
return false;
}
/* Get number of videos */
$books = simplexml_load_file('http://gdata.youtube.com/feeds/base/users/'.$channel.'/uploads?max-results=1&start-index=1');
$numb_videos = $books->children( 'openSearch', true )->totalResults;
settype($numb_videos, "integer");
$ids = array();
$i = 1;
for($i = 1; $i <= $numb_videos; $i++){
$books = simplexml_load_file('http://gdata.youtube.com/feeds/base/users/'.$channel.'/uploads?max-results=1&start-index='.$i);
$ApiLink = $books->entry->id;
settype($ApiLink, "string");
$ApiLink = str_replace("http://gdata.youtube.com/feeds/base/videos/", "", $ApiLink);
array_push($ids, $ApiLink);
}
return $ids;
}
用这个:
GET https://www.googleapis.com/youtube/v3/search?part=id&channelId=UC9MAhZQQd9egwWCxrwSIsJQ&maxResults=10&order=date&key={YOUR_API_KEY}
你会得到上述网址的结果如下:
200 OK
- Show headers -
{
"kind": "youtube#searchListResponse",
"etag": ""qQvmwbutd8GSt4eS4lhnzoWBZs0/WiiEAt3fgPkFw_831Iveo6mV-IU"",
"nextPageToken": "CAQQAA",
"pageInfo": {
"totalResults": 1046,
"resultsPerPage": 4
},
"items": [
{
"kind": "youtube#searchResult",
"etag": ""qQvmwbutd8GSt4eS4lhnzoWBZs0/OtU1Ja-W-gNf83iiXWzodKk3Ce0"",
"id": {
"kind": "youtube#video",
"videoId": "jKLMD-LXIgk"
}
},
{
"kind": "youtube#searchResult",
"etag": ""qQvmwbutd8GSt4eS4lhnzoWBZs0/EUhMCxemh2UGmf2ufGS0IYdcMUs"",
"id": {
"kind": "youtube#video",
"videoId": "glCQQeH_ddw"
}
},
{
"kind": "youtube#searchResult",
"etag": ""qQvmwbutd8GSt4eS4lhnzoWBZs0/2IMOnedhjKXxnFZy-PNg5o80kkY"",
"id": {
"kind": "youtube#video",
"videoId": "yB78MIcmDxs"
}
},
{
"kind": "youtube#searchResult",
"etag": ""qQvmwbutd8GSt4eS4lhnzoWBZs0/oEb7q9_GwGdXcHsvuRDuNmh_rGQ"",
"id": {
"kind": "youtube#video",
"videoId": "NnkDja1cXlo"
}
}
]
}
欲了解更多的参考,你可以在这里查看
$channelsResponse = $youtube->channels->listChannels('id,contentDetails', array(
'mine' => 'true'));
$playlistId = $channelsResponse['items']['contentDetails']['relatedPlaylists']['uploads'];
$searchResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
'playlistId' => $playlistId,
'maxResults' => 50,
'fields' => 'items(snippet(publishedAt,channelId,title,description,thumbnails(default),resourceId)),pageInfo,nextPageToken'));
echo json_encode($searchResponse['items']['contentDetails']['videoId']);
使用YouTube数据api v3来做到这一点。 这里是链接
链接地址: http://www.djcxy.com/p/28963.html