问题描述
首先,抱歉发布此内容,我不认为它是重复的,因为我从昨天开始一直在抓取 YouTube API 标记的问题,但找不到解决方法.
First off, apologize to post this, I don't think it is a duplicate since I kept crawling YouTube API tagged questions since yesterday and I couldn't find a fix.
我的问题是,即使 YouTube API 已被正式弃用,我还能继续使用它吗?原因是因为我有 2 个问题,我仍然无法在 V3 中找到修复它们,而我在 V2 中已经有了它们:列出频道的最后上传和热门上传.
My Question is, Can I keep using V2 of YouTube API even if it is officially deprecated ? the reason why is because I have 2 issues I still couldn't find a fix for them in V3 and I already have them in V2 : listing a channel's last uploads and popular uploads.
对于最后一次上传,在 V2 中我使用 http:///gdata.youtube.com/feeds/api/users/youtube/uploads?prettyprint=true ,而我添加 ?orderby=viewCount
来列出流行的.我在 V3 中找不到 alt [ 艰难我试过 https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&forUsername={Username}&maxResults=5&key={key} 但它不断列出视频来自我昨天访问的频道,即使我更改了用户名,让我认为链接或我的密钥有问题,顺便说一下服务器密钥]
For the last uploads, in V2 I use http://gdata.youtube.com/feeds/api/users/youtube/uploads?prettyprint=true , while I add ?orderby=viewCount
to list the popular ones. I couldn't find an alt in V3 [ Tough I tried https://www.googleapis.com/youtube/v3/videos?part=snippet&chart=mostPopular&forUsername={Username}&maxResults=5&key={key} but it keeps listing videos from a channel I visited yesterday even if I change the username, making me think there is problem with the link or my key, a server key by the way ]
有什么想法吗?
非常感谢!
推荐答案
与其使用视频->列表端点,不如使用搜索端点,如下所示:
Rather than using the videos->list endpoint, you should instead use the search endpoint, like this:
https://www.googleapis.com/youtube/v3/search?order=viewCount&part=snippet&channelId=UCuo5NTU3pmtPejmlzjCgwdw&maxResults=25&key={YOUR_API_KEY}
如果您愿意,您可以执行 order=date 来让它们按时间顺序而不是按受欢迎程度排序.您还可以使用许多其他参数……请参阅 https://developer.google.com/youtube/v3/docs/search/list 了解更多详情.
You can do order=date to have them ordered chronologically rather than by popularity if you'd rather. There are also a lot of other parameters you can use ... see https://developers.google.com/youtube/v3/docs/search/list for more details.
如果您不知道频道 ID,而只知道用户名,则您必须进行多次调用……调用此端点:
If you don't know the channel IDs, but only the usernames, you'll have to have multiple calls ... a call to this endpoint:
https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={username}&key={YOUR_API_KEY}
https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername={username}&key={YOUR_API_KEY}
这将返回一个包含通道 ID 的数据包.如果您想避免多次拨打电话或自己存储用户名/频道 ID,您可以将 'q' 参数设置为用户名进行视频搜索.它通常有效,但您可以通过这种方式获得无关的频道.
This will return a packet with the channel ID in it. If you'd like to avoid making multiple calls or storing the username/channelID on your own, you could do the video search with the 'q' parameter set to be the username. It often works but you can get extraneous channels that way.
这篇关于无法从 YouTube API 的 V2 迁移到 V3 - 无法列出频道的上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!