gpt4 book ai didi

ios - 如何使用 Swift 获取 youtube channel 的所有播放列表?

转载 作者:搜寻专家 更新时间:2023-11-01 05:53:40 24 4
gpt4 key购买 nike

我的问题不是关于从一般 channel 检索视频。我只想获取 channel 创建的所有“播放列表”,并检索每个播放列表的缩略图、标题和视频数。

这是一个 youtube channel 示例:

enter image description here

如您所见,创建了很多播放列表。

截至目前,我只能获取 channel 的最新上传视频,在本例中只有 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 来检索他们的播放列表,而不是检索 channel 的视频?

谢谢

最佳答案

我看到您正在使用链接中的 playlistItems。这只会从播放列表中抓取视频。

关注this linkon the bottom ,当您输入零件作为 snippet 和 channelid 作为 UCJKOvdk-nVzDAFR_9MF64sw 时。然后单击不使用 OAuth 执行。您将从该 channelid 获取所有播放列表的 json 对象。

在请求中,它向您显示:

GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCJKOvdk-nVzDAFR_9MF64sw&key={YOUR_API_KEY}

使用该 url,您应该能够获取它。

关于ios - 如何使用 Swift 获取 youtube channel 的所有播放列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35388909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com