通过 youtube api 将视频添加到播放列表时请求 URI 无效

发布于 2024-10-07 08:09:43 字数 1847 浏览 4 评论 0原文

在尝试使用 youtube gdata python api 将视频添加到我的播放列表时,我无法克服此错误。

gdata.service.RequestError: {'状态': 400, 'body': '无效的请求 URI', 'reason': '错误请求'}

似乎是相同的错误,但目前还没有解决方案。大家有什么帮助吗?

 import getpass
 import gdata.youtube
 import gdata.youtube.service

 yt_service = gdata.youtube.service.YouTubeService()

 # The YouTube API does not currently support HTTPS/SSL access.
 yt_service.ssl = False
 yt_service = gdata.youtube.service.YouTubeService()
 yt_service.email = #myemail
 yt_service.password = getpass.getpass()
 yt_service.developer_key = #mykey
 yt_service.source = #text
 yt_service.client_id= #text
 yt_service.ProgrammaticLogin()

 feed = yt_service.GetYouTubePlaylistFeed(username='default')
 # iterate through the feed as you would with any other
 for entry in feed.entry:
     if (entry.title.text == "test"):
         lst = entry;
         print entry.title.text, entry.id.text

 custom_video_title = 'my test video on my test playlist'  
 custom_video_description = 'this is a test video on my test playlist'  
 video_id = 'Ncakifd_16k'  
 playlist_uri = lst.id.text    

 playlist_video_entry = yt_service.AddPlaylistVideoEntryToPlaylist(playlist_uri, video_id, custom_video_title, custom_video_description)    

 if isinstance(playlist_video_entry, gdata.youtube.YouTubePlaylistVideoEntry):
 print 'Video added'

令人困惑的是,更新播放列表有效,但添加视频却无效。

 playlist_entry_id = lst.id.text.split('/')[-1]
 original_playlist_description = lst.description.text
 updated_playlist = yt_service.UpdatePlaylist(playlist_entry_id,'test',original_playlist_description,playlist_private=False)

video_id 没有错误,因为它是示例代码中的视频。我在这里缺少什么?有人帮忙!

谢谢。

I have been unable to overcome this error while trying to add a video to my playlist using the youtube gdata python api.

gdata.service.RequestError: {'status':
400, 'body': 'Invalid request URI',
'reason': 'Bad Request'}

This seems to be the same error, but there are no solutions as yet. Any help guys?

 import getpass
 import gdata.youtube
 import gdata.youtube.service

 yt_service = gdata.youtube.service.YouTubeService()

 # The YouTube API does not currently support HTTPS/SSL access.
 yt_service.ssl = False
 yt_service = gdata.youtube.service.YouTubeService()
 yt_service.email = #myemail
 yt_service.password = getpass.getpass()
 yt_service.developer_key = #mykey
 yt_service.source = #text
 yt_service.client_id= #text
 yt_service.ProgrammaticLogin()

 feed = yt_service.GetYouTubePlaylistFeed(username='default')
 # iterate through the feed as you would with any other
 for entry in feed.entry:
     if (entry.title.text == "test"):
         lst = entry;
         print entry.title.text, entry.id.text

 custom_video_title = 'my test video on my test playlist'  
 custom_video_description = 'this is a test video on my test playlist'  
 video_id = 'Ncakifd_16k'  
 playlist_uri = lst.id.text    

 playlist_video_entry = yt_service.AddPlaylistVideoEntryToPlaylist(playlist_uri, video_id, custom_video_title, custom_video_description)    

 if isinstance(playlist_video_entry, gdata.youtube.YouTubePlaylistVideoEntry):
 print 'Video added'

The confounding thing is that updating the playlist works, but adding a video does not.

 playlist_entry_id = lst.id.text.split('/')[-1]
 original_playlist_description = lst.description.text
 updated_playlist = yt_service.UpdatePlaylist(playlist_entry_id,'test',original_playlist_description,playlist_private=False)

The video_id is not wrong because its the video from the sample code. What am I missing here? Somebody help!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2024-10-14 08:09:43

Gdata似乎使用v1 API。因此,相关文档位于:http://code.google.com /apis/youtube/1.0/developers_guide_protocol.html#Retriving_a_playlist

这意味着,您的“playlist_uri”不应采用“lst.id.text”的值,而应采用“feedLink”元素的“href”属性为了与“AddPlaylistVideoEntryToPlaylist”一起使用

即使您碰巧使用 v2 API,您也应该按照文档中的说明从“content”元素的“src”属性中获取 URI,您可以通过在上面的 URL 中替换 2.0 来获得! (所以不允许我放置两个超链接,因为我没有足够的声誉!:))

Gdata seems to use v1 API. So, the relevant documentation is here: http://code.google.com/apis/youtube/1.0/developers_guide_protocol.html#Retrieving_a_playlist

This means, your "playlist_uri" should not take the value of "lst.id.text", but should take the "feedLink" element's "href" attribute in order to be used with "AddPlaylistVideoEntryToPlaylist"

Even if you happen to use v2 API, you should take the URI from the "content" element's "src" attribute as explained in the documentation, you get by substituting 2.0, in the above URL! (SO doesn't allow me to put two hyperlinks because i don't have enough reputations! :))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文