我使用https://github.com/google/google-api-dotnet-client从Youtube频道获取一些视频。
这是我的代码:
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApplicationName = "My Application",
ApiKey = "MyKey",
GZipEnabled = true
});
var searchResultList = youtubeService.Search.List("id");
searchResultList.ChannelId = "mychannelid";
searchResultList.Order = SearchResource.ListRequest.OrderEnum.Date;
searchResultList.Type = "video";
searchResultList.MaxResults = 50;
var ids = string.Join(",", searchResultList.Execute().Items.Select(x => x.Id.VideoId));
var videoRequest = youtubeService.Videos.List("snippet, contentDetails");
videoRequest.Id = ids;
videoRequest.MaxResults = 50;
return videoRequest.Execute().Items.ToList();
应用程序每20分钟执行一次此代码。因此,请求数量不能超过配额数量。 但是,不幸的是,我经常收到这个错误:
Message: Google.Apis.Requests.RequestError
Bad Request [400]
Errors [
Message[Bad Request] Location[ - ] Reason[keyInvalid] Domain[usageLimits]
]
Exception type: Google.GoogleApiException
Stack Trace:
at Google.Apis.Requests.ClientServiceRequest`1.Execute() in C:\Users\mdril\Documents\GitHub\google-api-dotnet-client\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 102
这里有一些类似的问题,但它没有帮助。