PEPEGA
PEPEGA

Reputation: 2281

Youtube API returns no results

I am having problems loading a playlist of videos from Youtube. I follow this guide but cant figure out what is wrong because I don't get an error.

 var YouTubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "MyAPIID"}); 
 var ChannelListRequest = YouTubeService.Channels.List("contentDetails");
 ChannelListRequest.ForUsername = "YoutubeUser";    
 var ListResponse = ChannelListRequest.Execute();

 foreach (var channel in ListResponse.Items) //No content in ListResponse.Items

When I execute the request it returns a empty response. The API Id is correct because it becomes error if I use a old one. I have tried with the username and id from the channel but none worked. What am I missing?

Upvotes: 0

Views: 603

Answers (1)

Niels de Schrijver
Niels de Schrijver

Reputation: 335

Alright I tried some things and I managed to retrieve my playlists of my channel like so:

var service = new YouTubeService(new BaseClientService.Initializer()
{
     ApiKey = "yourapikey",
     ApplicationName = this.GetType().Name
});

var playListRequest = service.Playlists.List("snippet");
playListRequest.ChannelId = "yourchannelid";
var result = await playListRequest.ExecuteAsync();

With the playlist Id's you get from this response you can retrieve the video's like so:

var playListItemsRequest = service.PlaylistItems.List("snippet");
playListItemsRequest.PlaylistId = "yourplaylistid";
var result = await playListItemsRequest.ExecuteAsync();

Upvotes: 1

Related Questions