我在加载Youtube上的视频播放列表时遇到问题。我关注this guide,但无法弄清楚出了什么问题,因为我没有收到错误。
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
当我执行请求时,它返回一个空响应。 API ID是正确的,因为如果我使用旧的ID会出错。我已尝试使用频道中的用户名和ID但没有效果。我错过了什么?
答案 0 :(得分:1)
好吧我尝试了一些东西,我设法检索了我的频道播放列表,如下:
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();
根据您从此回复获得的播放列表ID,您可以检索视频,如下所示:
var playListItemsRequest = service.PlaylistItems.List("snippet");
playListItemsRequest.PlaylistId = "yourplaylistid";
var result = await playListItemsRequest.ExecuteAsync();