问题
I've been struggling with what I thought would be a simple task: Adding a video to a youtube playlist. I've got the uri and video id, so this should work, right?
uri = "http://gdata.youtube.com/feeds/api/users/dolkarr/playlists/AAnCXJ-nfQZwZYqo69euVZVyJ_XofIJs"
vid = "dmoDLyiQYKw"
video = yt_service.AddPlaylistVideoEntryToPlaylist(uri, vid)
But it returns this error response:
gdata.service.RequestError: {'status': 400, 'body': 'Invalid request URI', 'reason': 'Bad Request'}
After a bit of research, I found out that it only works for the 16 character playlist IDs which some of my older playlists have. Prefixing "PL" makes no difference.
Someone "solved" the problem by using a playlist ID that doesn't contain "-", but I am unable to create such a playlist! All of them start with AAnCXJ-nfQ
...
So, all I'm asking... is there any possibility to make this work? Either by somehow creating a playlist with old-style ID or making it accept these... I need to create several playlists with 200 videos each and I really don't want to fill them all manually... Thanks for response!
回答1:
uri = "http://gdata.youtube.com/feeds/api/users/dolkarr/playlists/AAnCXJ-nfQZwZYqo69euVZVyJ_XofIJs"
you should remove user/userid, become
uri = "http://gdata.youtube.com/feeds/api/playlists/AAnCXJ-nfQZwZYqo69euVZVyJ_XofIJs"
Check it out: https://developers.google.com/youtube/1.0/developers_guide_python#AddVideoToPlaylist
回答2:
For the best result, I'd suggest you to use Data API v3
There is a great Python example that accomplished what you are trying to do. 'https://developers.google.com/youtube/v3/docs/playlistItems/insert#examples'
This should get you started really quick.
回答3:
I think that the best practice is always use the prefix PL:
from this article:
http://apiblog.youtube.com/2012/08/playlists-now-with-more-pl.html
While we will continue to support using unprefixed playlist IDs as metadata or in API request URLs for the time being, at some point in the future we may require the “PL” prefix to be used whenever a playlist ID is provided. We’ll provide additional guidance if we do decide to stop supporting requests with unprefixed playlist IDs.
but problems have been reported
https://groups.google.com/forum/#!topic/youtube-api-gdata/0c6dorRZ7bg
I believe that if you use the PL prefix and you get an error, then you must report a possible bug
来源:https://stackoverflow.com/questions/14713784/youtube-api-adding-videos-to-a-playlist-with-the-new-32-character-playlist-id