Richard Otvos
Richard Otvos

Reputation: 196

Retriving Youtube playlist information trough You Tube API (python)

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!

Upvotes: 3

Views: 3512

Answers (1)

Blender
Blender

Reputation: 298512

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.

Upvotes: 4

Related Questions