我的问题不是关于从某个频道检索视频。我只想获取频道创建的所有“播放列表”,并检索每个播放列表的缩略图,标题和视频数量。
这是一个YouTube频道示例:
如您所见,有许多创建的播放列表。
截至目前,我只能获取某个频道的最新上传视频,在这种情况下,只有5个。
使用以下代码:
let urlString = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=\(playlistID)&key=\(apiKey)"
// Create a NSURL object based on the above string.
let targetURL = NSURL(string: urlString)
// Fetch the playlist from Google.
performGetRequest(targetURL, completion: { (data, HTTPStatusCode, error) -> Void in
if HTTPStatusCode == 200 && error == nil
{
// Convert the JSON data into a dictionary.
let resultsDict = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as! Dictionary<NSObject, AnyObject>
print("resultsDict = \(resultsDict)")
......
}
else
{
print("HTTP Status Code = \(HTTPStatusCode)")
print("Error while loading channel videos: \(error)")
}
})
输出resultsDict
:
[etag: "DsOZ7qVJA4mxdTxZeNzis6uE6ck/0JswUeQp5Wp8607mWPWAfIZaNnM", kind: youtube#playlistItemListResponse, items: (
{
etag = "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/hQUAFFn45u2V47VqvBg1urbZevU\"";
id = "UUS8cX3kg_pL2jw7cOjGoiBw9Ri_jF-DJp";
kind = "youtube#playlistItem";
snippet = {
channelId = "UCJKOvdk-nVzDAFR_9MF64sw";
channelTitle = AppSpy;
description = "James (@Metal_Slag) punches blocks and butt-stomps critters in neon platformer Super Phantom Cat.\n\nDOWNLOAD FROM THE APP STORE:\nhttps://itunes.apple.com/us/app/super-phantom-cat-be-jumpin/id1041873285?mt=8\n\nSUBSCRIBE TO APPSPY:\nhttps://www.youtube.com/subscription_center?add_user=appspy\n\nVISIT:\nhttp://www.pocketgamer.co.uk";
playlistId = "UUJKOvdk-nVzDAFR_9MF64sw";
position = 0;
publishedAt = "2016-02-12T15:59:10.000Z";
resourceId = {
kind = "youtube#video";
videoId = qkMOjc02NRg;
};
thumbnails = {
default = {
height = 90;
url = "https://i.ytimg.com/vi/qkMOjc02NRg/default.jpg";
width = 120;
};
high = {
height = 360;
url = "https://i.ytimg.com/vi/qkMOjc02NRg/hqdefault.jpg";
width = 480;
};
maxres = {
height = 720;
url = "https://i.ytimg.com/vi/qkMOjc02NRg/maxresdefault.jpg";
width = 1280;
};
medium = {
height = 180;
url = "https://i.ytimg.com/vi/qkMOjc02NRg/mqdefault.jpg";
width = 320;
};
standard = {
height = 480;
url = "https://i.ytimg.com/vi/qkMOjc02NRg/sddefault.jpg";
width = 640;
};
};
title = "MEW-RIO? | Super Phantom Cat iPhone & iPad Preview";
};
},
....
// Display info for most recent remaining 4 videos
....
, nextPageToken: CAUQAA, pageInfo: {
resultsPerPage = 5;
totalResults = 3966;
}]
除了获取频道的视频外,我如何使用youtube api v3来获取其播放列表?
谢谢
我看到您正在使用playlistItems
您的链接。这只会从播放列表中抓取视频。
当您输入part as和channelid为时,请点击此链接并在底部。然后,单击不使用OAuth即可执行。您将从该channelid获取所有播放列表的json对象。snippet
UCJKOvdk-nVzDAFR_9MF64sw
在请求中它向您显示:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCJKOvdk-nVzDAFR_9MF64sw&key={YOUR_API_KEY}
使用该网址,您应该可以抓取它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句