代码之家  ›  专栏  ›  技术社区  ›  Gonzalo

404获取私有YouTube视频时,即使使用gdata python客户端使用所有者的帐户登录

  •  2
  • Gonzalo  · 技术社区  · 16 年前

    YouTube 视频设置为私有,我尝试使用 gdata Python API a 404 即使我使用拥有该视频的帐户进行了编程登录:

    from gdata.youtube import service
    yt_service = service.YouTubeService(email=my_email,
                                        password=my_password,
                                        client_id=my_client_id,
                                        source=my_source,
                                        developer_key=my_developer_key)
    yt_service.ProgrammaticLogin()
    yt_service.GetYouTubeVideoEntry(video_id='IcVqemzfyYs')
    ---------------------------------------------------------------------------
    RequestError                              Traceback (most recent call last)
    
    <ipython console> 
    
    /usr/lib/python2.4/site-packages/gdata/youtube/service.pyc in GetYouTubeVideoEntry(self, uri, video_id)
        203     elif video_id and not uri:
        204       uri = '%s/%s' % (YOUTUBE_VIDEO_URI, video_id)
    --> 205     return self.Get(uri, converter=gdata.youtube.YouTubeVideoEntryFromString)
        206 
        207   def GetYouTubeContactFeed(self, uri=None, username='default'):
    
    /usr/lib/python2.4/site-packages/gdata/service.pyc in Get(self, uri, extra_headers, redirects_remaining, encoding, converter)
       1100             'body': result_body}
       1101     else:
    -> 1102       raise RequestError, {'status': server_response.status,
       1103           'reason': server_response.reason, 'body': result_body}
       1104 
    
    RequestError: {'status': 404, 'body': 'Video not found', 'reason': 'Not Found'}
    

    这种情况每次都会发生,除非我进入我的YouTube帐户(通过YouTube网站)并将其设置为public,然后我可以使用pythonapi将其设置为private并返回public。

    提前谢谢。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Gonzalo    16 年前

    显然YouTube数据API doesn't allow this (yet) 获取YouTubeUserFeed YouTube服务 实例以获取我需要的所有视频条目的列表(无论它们是私有的还是公共的):

    from gdata.youtube import service
    VIDEO_ID = 'IcVqemzfyYs'
    yt_service = service.YouTubeService(email=my_email,
                                    password=my_password,
                                    client_id=my_client_id,
                                    source=my_source,
                                    developer_key=my_developer_key)
    yt_service.ProgrammaticLogin()
    userfeed = yt_service.GetYouTubeUserFeed(username=my_email[:my_email.index('@')])
    video_entry = reduce(lambda e1, e2: e1 if e1.id.text.endswith(VIDEO_ENTRY) else (e2 if e2.id.text.endswith(VIDEO_ENTRY) else None),
                         userfeed.entry)
    

    希望这能帮助有同样问题的人:)