Reputation: 37
I am using a PHP script to find all the playlists that a particular user ID has uploaded. The problem is the script is not returning all the playlists, but only some of them .
I want to get all the playlists, but not all of them are fetched.
Check it out here : Link
Here is my code ( GET ARGUMENT IS the /channelname ):
<?php
header('Content-Type: text/html; charset=utf-8');
$feedUrl='https://gdata.youtube.com/feeds/api/users/'.$_GET['id'].'/playlists?v=2&alt=json';
$data = json_decode(file_get_contents($feedUrl),true);
$info = $data["feed"];
$entry = $info["entry"];
$nEntry = count($entry);
/* echo "Playlist Name: ".$info["title"]['$t'].'<br/>';
echo "Number of Videos (".$nVideo."):<br/>";*/
$MainFeed=array();
for($i=0;$i<$nEntry;$i++){
$thumbId=split('/',$entry[$i]['media$group']['media$thumbnail'][0]['url'] );
$thumbId=$thumbId[4];
$playList=array(
'title' => $entry[$i]['title']['$t'],
'playlistId' => $entry[$i]['yt$playlistId']['$t'],
'published'=>$entry[$i]['published']['$t'],
'thumbId'=>$thumbId,
'videosCount'=>$entry[$i]['yt$countHint']['$t'],
'videos'=>getVideos($entry[$i]['yt$playlistId']['$t'])
);
array_push($MainFeed,$playList);
//print_r($entry[$i]);
/*
echo "Name: ".$entry[$i]['title']['$t'].'<br/>';
echo 'http://www.youtube.com/playlist?list='.$entry[$i]['yt$playlistId']['$t'].'&feature=plcp'.'<br/>';
echo '<br>$thumbId : '.$thumbId .'<br>';
echo "playlistId: ".$entry[$i]['yt$playlistId']['$t']."<br />";
echo "published: ".$entry[$i]['published']['$t']."<br />";
*/
// break;
}
echo '{ "feed":'.json_encode($MainFeed).'}';
function getVideos($playListId){
$feedUrl='https://gdata.youtube.com/feeds/api/playlists/'.$playListId.'?v=2&alt=json';
$data = json_decode(file_get_contents($feedUrl),true);
$info = $data["feed"];
$entry = $info["entry"];
$nEntry = count($entry);
$PLayListVideos=array();
for($i=0;$i<$nEntry;$i++){
$video = array(
'title' => $entry[$i]['title']['$t'],
'description' => $entry[$i]['media$group']['media$description']['$t'],
'published' =>$entry[$i]['published']['$t'],
'duration'=>$entry[$i]['media$group']['yt$duration']['seconds'],
'videoid'=>$entry[$i]['media$group']['yt$videoid']['$t'],
'favoriteCount'=>$entry[$i]['yt$statistics']['favoriteCount'],
'viewCount'=>$entry[$i]['yt$statistics']['viewCount'],
'numDislikes'=>$entry[$i]['yt$rating']['numDislikes'],
'numLikes'=>$entry[$i]['yt$rating']['numLikes'],
'rating'=>$entry[$i]['gd$rating']['average'],
'max'=>$entry[$i]['gd$rating']['max'],
'min'=>$entry[$i]['gd$rating']['min'] ,
'numRaters'=>$entry[$i]['gd$rating']['numRaters'] ,
'rtsp1'=>$entry[$i]['media$group']['media$content']['1']['url'],
'rtsp2'=>$entry[$i]['media$group']['media$content']['2']['url'],
);
array_push($PLayListVideos,$video);
/*
echo "Name: ".$entry[$i]['title']['$t'].'<br/>';
echo "published: ".$entry[$i]['published']['$t']."<br />";
echo "duration : ".$entry[$i]['media$group']['yt$duration']['seconds'].'<br/>';
echo "videoid : ".$entry[$i]['media$group']['yt$videoid']['$t'].'<br/>';
echo "Image 90 : ".$entry[$i]['media$group']['media$thumbnail'][0]['url'].'<br/>';
echo "Image 180 : ".$entry[$i]['media$group']['media$thumbnail'][1]['url'].'<br/>';
echo "Image 360 : ".$entry[$i]['media$group']['media$thumbnail'][2]['url'].'<br/>';
echo "favoriteCount : ".$entry[$i]['yt$statistics']['favoriteCount'] .'<br/>';
echo "viewCount : ".$entry[$i]['yt$statistics']['viewCount'] .'<br/>';
echo "numDislikes : ".$entry[$i]['yt$rating']['numDislikes'] .'<br/>';
echo "numLikes : ".$entry[$i]['yt$rating']['numLikes'] .'<br/>';
echo "rating : ".$entry[$i]['gd$rating']['average'] .'<br/>';
echo "max : ".$entry[$i]['gd$rating']['max'] .'<br/>';
echo "min : ".$entry[$i]['gd$rating']['min'] .'<br/>';
echo "numRaters : ".$entry[$i]['gd$rating']['numRaters'] .'<br/>';
echo "rtsp1 : ".$entry[$i]['media$group']['media$content']['1']['url'] .'<br/>';
echo "rtsp2 : ".$entry[$i]['media$group']['media$content']['2']['url'] .'<br/>';
*/
//print_r($entry[$i]);
}
return $PLayListVideos;
}
?>
How can I make changes to get all the playlists the channel has?
Upvotes: 1
Views: 1310
Reputation: 1538
Doing a necro on this old question but I've been researching this myself. When you're trying to access someone else's playlists, you only see the public ones. The private ones might include the history, favorites, and to-watch playlists. There are also others which might be private. So you're not going to see these unless you use the query to see "Mine" playlists. There are also the Saved playlists - these are playlists of others where someone has saved a link on their own channel. So you might come to my channel looking for videos on development and I might have saved references to other channels - so I don't need to host the vids in my own playlists, I'll just trust others to maintain their lists. Anyway, this feature doesn't seem to have access via the API per this recognized issue:
https://code.google.com/p/gdata-issues/issues/detail?id=6610
So as a final answer to "How can I make changes to get all the playlists the channel has?", the answer is that you can't. There will probably be private playlists that you can't see, and this bug prevents you from seeing the saved playlists.
Upvotes: 0
Reputation: 37
max-results ... specifies the maximum number of results that should be included in the result set. This parameter works in conjunction with the start-index parameter to determine which results to return ... The default value of this parameter is 25, and the maximum value is 50...
Use this URL to get the first 25 videos (explicitly specifying max-results is a good idea):
http://gdata.youtube.com/feeds/api/playlists/FLz97F7dMxBNOfGYu3rx8aCw?max-results=25&start-index=1
To get the next 25 videos specify the start-index=26:
http://gdata.youtube.com/feeds/api/playlists/FLz97F7dMxBNOfGYu3rx8aCw?max-results=25&start-index=26
Notes:
Upvotes: 1