编程语言
首页 > 编程语言> > 通过You Tube API(Python)检索Youtube播放列表信息

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

作者:互联网

使用Python YouTube API获取播放列表中视频的标题时,我有些问题.我已经正确配置了环境,当我从API文档中复制示例时,该环境也可用于添加的播放列表ID,但是当我尝试使用其他播放列表中的一个时,会出现错误.

这是我写的一些代码:(在本示例中,我尝试获取视频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

这是我得到的错误:

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

我对此感到非常沮丧,希望能有所帮助.谢谢!

解决方法:

在您的请求URI中删除PL:

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

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

您也可以只对字符串执行.replace(‘playlists / PL’,’playlists /’).

标签:api,youtube-api,python
来源: https://codeday.me/bug/20191102/1988748.html