通过 You Tube API 检索 Youtube 播放列表信息 (python)

发布于 2024-12-10 14:49:18 字数 907 浏览 1 评论 0原文

我在使用 Python YouTube API 获取播放列表中视频的标题时遇到了一些问题。我已经正确配置了环境,而且当我从 API 文档复制示例时,它适用于添加的播放列表 ID,但是当我尝试使用其他播放列表中的播放列表时,我收到错误。

这是我写的一些代码:(在这个例子中,我尝试从这里获取视频的标题< /a>)

import gdata.youtube
import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService()
yt_service.ssl = True

# a typical playlist URI
playlist_uri = "http://gdata.youtube.com/feeds/api/playlists/PLCD939C4D974A5815"

playlist_video_feed = yt_service.GetYouTubePlaylistVideoFeed(playlist_uri)

# iterate through the feed as you would with any other
for playlist_video_entry in playlist_video_feed.entry:
    print playlist_video_entry.title.text

这是我得到的错误:

RequestError: {'status': 400, 'body': 'Invalid playlist id', 'reason': 'Bad Request'}

我对此感到非常沮丧,希望得到一些帮助。谢谢你!

I have a bit of a problem with using the Python YouTube API to get the title of the videos in the playlist. I have the enviroment configured correctly, also when I copied the example from the API documentation it works for the added playlist id, but when I try to use one from an other playlist I get an error.

Here is some code I wrote: (In this example I try to get the titles of the videos from here)

import gdata.youtube
import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService()
yt_service.ssl = True

# a typical playlist URI
playlist_uri = "http://gdata.youtube.com/feeds/api/playlists/PLCD939C4D974A5815"

playlist_video_feed = yt_service.GetYouTubePlaylistVideoFeed(playlist_uri)

# iterate through the feed as you would with any other
for playlist_video_entry in playlist_video_feed.entry:
    print playlist_video_entry.title.text

Here is the error I get:

RequestError: {'status': 400, 'body': 'Invalid playlist id', 'reason': 'Bad Request'}

I'm quite frustrated with this and would appreciate some help. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2024-12-17 14:49:19

删除请求 URI 中的 PL

playlist_uri = "http://gdata.youtube.com/feeds/api/playlists/CD939C4D974A5815"

我不确定 YouTube 为什么需要采用这种格式,但确实需要如此。

您也可以在字符串上执行 .replace('playlists/PL', 'playlists/')

Remove PL in your request URI:

playlist_uri = "http://gdata.youtube.com/feeds/api/playlists/CD939C4D974A5815"

I'm not sure why YouTube needs it to be in that format, but it needs to be.

You can also just do a .replace('playlists/PL', 'playlists/') on your string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文