3
votes

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

2
What's your channel ID? That way we can run the same tests you are.jlmcdonald

2 Answers

10
votes

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}
0
votes

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;
    }

}