我一直在查看有关如何获取 channel 的 JSON 视频列表的 Google 文档。我想出了如何获取带有缩略图和标题等的视频列表......但我无法找到如何获取 VIDEO MP4(或任何其他格式)的 URL。
你看我需要在 iOS 应用程序中播放视频,我的应用程序需要实际的 VIDEO URL,而不是一些烦人的 url,它只返回缩略图或播放列表的列表......
我在网上找到了这些说明,它们与最后一部分不同:
You have to get the upload playlist id to get each videos uploaded. To get that, you need to get the channel id. After you have the playlist id from the channel id, it is pretty simple. I have written out the steps for all three below.
Also, we offer PubSubHubBub which allows you to be alerted every time a new video is added to a channel, or you could use SUP (V2) to see which resources have changed before making the calls.
Instructions to get video ids for all uploaded videos for a channel in V3
Get the channel id for the channel you want (you probably only need to do this once, then you can save it)
Use search.list Set type to channel Set q to the name of the channel you want Grab the channel id (something like this: "channelId": "UC0X2VuXXXXXXXXXXXXXXXX") Get the playlist id for the channel uploads using the channel id from step 1 (you probably only need to do this once, then you can save it)
Use channels.list Set id to UC0X2VuXXXXXXXXXXXXXXXX from step 2 Grab the uploads key from contentDetails (something like this: "uploads": "UU0XXXXXXXXXXXXXXXXXXXX") Get the videos via the playlistitems in the playlist using the playlist id from step 2
Use playlistItems.list Set playlistId to UU0XXXXXXXXXXXXXXXXXXXX from step 2 Go through each PlaylistItem and pull out the video id
如您所见,最后一部分说要通过播放列表项并提取视频 ID。我已经这样做了,但是我需要对视频 ID 做什么才能获取视频 URL ???
谁能帮我?
谢谢,丹。
最佳答案
NSString *youtubeHTML = [[NSString alloc] initWithFormat:@"\
<html><head>\
<style type=\"text/css\">\
body { background-color: transparent;\
color: white; \
}\
</style>\
</head><body style=\"margin:0\">\
<iframe class=\"youtube-player\" width=\"280\" height=\"210\" src=\"http://www.youtube.com/embed/%@?\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>\
</body></html>", videoID];
您还可以使用 URL 显示/隐藏内容,hd,在特定时间开始。
youTubeView = [[UIWebView alloc] initWithFrame:CGRectMake(yourframe)];
[youTubeView loadHTMLString:youtubeHTML baseURL:nil];
关于ios - 获取 YouTube 视频 URL - 数据 API 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824905/