我尝试收到属于首选类别的视频的完整列表,但我遇到了问题。首先,我检查类别:
func getCategories(complishion: ([CategoriesTitle]) -> Void ){
let youTubeURLCategoriesAdress = "https://www.googleapis.com/youtube/v3/videoCategories?part=snippet®ionCode=US&key=\(YOUTUBE_ACCESS_KEY)"
Alamofire.request(.GET, youTubeURLCategoriesAdress).responseJSON(completionHandler: { (response: Response<AnyObject, NSError>) in
switch response.result {
case .Success:
if let json = response.result.value{
if let items = json["items"]{
print(items)
guard let categories: Array<CategoriesTitle> = Mapper<CategoriesTitle>().mapArray(items) else {
return
}
dispatch_async(dispatch_get_main_queue(), {
categoriesTitles(categories)
})
}
}
}
在这种情况下,我收到所有结果。下面是一个例子:
etag = "\"5g01s4-wS2b4VpScndqCYc5Y-8k/nqRIq97-xe5XRZTxbknKFVe5Lmg\"";
id = 10;
kind = "youtube#videoCategory";
snippet = {
assignable = 1;
channelId = "UCBR8-60-B28hp2BmDPdntcQ";
title = Music;
};
然后我不知道应该如何向YT API发送请求,并询问有关类别&#39; Music&#39;的一部分的完整视频列表。在这种情况下,id = 10。有任何想法吗?
答案 0 :(得分:1)
以下请求会返回“10”类别中的所有视频 - 您需要将type
设置为video
https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoCategoryId=10&key=
{YOUR_API_KEY}