4

I have to retrieve all video of my channel with Youtube API. All videos are published on Youtube and I can see them correctly.

I tried to make the request directly from this page: https://developers.google.com/youtube/v3/docs/search/list and this is the example request: GET http s://www.googleapis.com/youtube/v3/search?part=snippet&channelId=myChannelID&maxResults=50&key={YOUR_API_KEY}

Request doesn't retrieve all videos, it returns only 7 on the total of 9. All videos have the same configuration. Missing videos are always the same.

If I use the video API passing the ID of one of those videos excluded from the search response, it returns a correct response and it belong correctly to my channel: https://developers.google.com/youtube/v3/docs/videos/list#try-it

Someone can help me?

thank you in advance

Francesco

Devs Yakamoz
  • 43
  • 1
  • 3

2 Answers2

11

The answer to "How do I obtain a list of all videos in a channel using the YouTube Data API v3?" here may be what you need. Look especially at the video linked to in the answer.

To summarize, to get all the uploads from a channel, you need to get the items from the uploads playlist for the channel using playlistItems.list on that playlist's ID rather than calling search.list on the channel ID.

Try this two-step approach:

  1. Get the ID of your channel's uploads playlist using the channels.list API call: GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={YOUR_CHANNEL_ID}&key={YOUR_API_KEY}
  2. Get the videos from the uploads playlist using the playlistItems.list call: GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=3&playlistId={YOUR_PLAYLIST_ID}&key={YOUR_API_KEY}
Community
  • 1
  • 1
mmirus
  • 191
  • 1
  • 6
  • 1
    Thank you, it was my second solution to solve the problem. Even if I didn't understand why search API doesn't work properly. – Devs Yakamoz May 18 '15 at 13:16
  • @mmirus playlistItems.list() works from some uploadId , throws 404 for other saying playlist not found. search.list() works for all but returns old videos. – ishandutta2007 Apr 25 '17 at 03:06
  • @DevsYakamoz: did you find a way to list all videos (especially chronologically) using search? – ishandutta2007 Apr 25 '17 at 03:07
  • 1
    @mmirus in the playlistItems endpoint how to use some date range parameter like publishAfter/ publishedBefore. I tried It, not working So how I fetch all the videos of a channel. – Harsh sachdev Apr 22 '19 at 07:14
  • 2
    This solves my problem as well when searching for video's of a channelId and order on date. Which gives unreliable results (randomly missing latest video's). And the quota cost for getting the channels lists and playlist items is only 1 for each call. Which is important nowadays when the daily quota is decreased to 10.000 – A.W. Sep 13 '19 at 08:03
0

try this

async static Task<IEnumerable<YouTubeVideo>> GetVideosList(Configurations configurations, string searchText = "", int maxResult = 20)
{
    List<YouTubeVideo> videos = new List<YouTubeVideo>();

    using (var youtubeService = new YouTubeService(new BaseClientService.Initializer()
    {
        ApiKey = configurations.ApiKey
    }))
    {
        var searchListRequest = youtubeService.Search.List("snippet");
        searchListRequest.Q = searchText;
        searchListRequest.MaxResults = maxResult;
        searchListRequest.ChannelId = configurations.ChannelId;
        searchListRequest.Type = "video";
        searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date;// Relevance;


        var searchListResponse = await searchListRequest.ExecuteAsync();


        foreach (var responseVideo in searchListResponse.Items)
        {
            videos.Add(new YouTubeVideo()
            {
                Id = responseVideo.Id.VideoId,
                Description = responseVideo.Snippet.Description,
                Title = responseVideo.Snippet.Title,
                Picture = GetMainImg(responseVideo.Snippet.Thumbnails),
                Thumbnail = GetThumbnailImg(responseVideo.Snippet.Thumbnails)
            });
        }

        return videos;
    }

}
sgpalit
  • 2,676
  • 2
  • 16
  • 22
Omar Maher
  • 45
  • 4