2011-10-19 40 views
3

我在使用Python YouTube API獲取播放列表中的視頻標題時遇到了一些問題。我的環境配置正確,當我從API文檔中複製該示例時,它爲添加的播放列表ID起作用,但是當我嘗試從其他播放列表中使用某個播放列表時,出現錯誤。回覆Youtube播放列表信息槽You Tube API(python)

下面是一些代碼,我寫道:(在這個例子中,我試圖讓視頻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'} 

我對此非常沮喪,並希望得到一些幫助。謝謝!

回答

4

刪除PL在請求URI:

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

我不知道爲什麼YouTube的需要它是該格式,但它需要。

你也可以在你的字符串上做一個.replace('playlists/PL', 'playlists/')

+0

你是一位天才先生! 謝謝。 –

+0

我猜想,幸運的是我的部分。我甚至從未使用YouTube API;) – Blender