【问题标题】:Invalid request URI while adding a video to playlist via youtube api通过 youtube api 将视频添加到播放列表时请求 URI 无效
【发布时间】:2011-05-24 01:46:59
【问题描述】:

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

gdata.service.RequestError: {'status': 400, 'body': '无效的请求 URI', “原因”:“错误请求”}

This 似乎是同样的错误,但目前还没有解决方案。有帮助吗?

 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 没有错,因为它是示例代码中的视频。我在这里想念什么?有人帮忙!

谢谢。

【问题讨论】:

    标签: python youtube-api gdata-api


    【解决方案1】:

    Gdata 似乎使用 v1 API。所以,相关文档在这里:http://code.google.com/apis/youtube/1.0/developers_guide_protocol.html#Retrieving_a_playlist

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

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

    【讨论】:

      猜你喜欢
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 2018-03-10
      • 2018-02-14
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2014-02-09
      相关资源
      最近更新 更多