Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 219
Richard Otvos Avatar asked Jan 20 '26 11:01

Richard Otvos


1 Answers

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.

like image 60
Blender Avatar answered Jan 23 '26 01:01

Blender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!