python - 即使使用 gdata-python-client 使用所有者的帐户登录,获取私有(private) YouTube 视频时也会出现 404

标签 python gdata-api youtube-api

如果 YouTube视频设置为私有(private),我尝试使用 gdata Python API 获取它引发了 404 RequestError,即使我已经使用拥有该视频的帐户进行了编程登录:

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 网站)并将其设置为公开,之后我可以使用 Python API 将其设置为私有(private)并恢复为公开。

我是否遗漏了一个步骤,或者是否有其他(或任何)方法从 API 获取设置为私有(private)的 YouTube 视频?

提前致谢。

最佳答案

显然是 YouTube 数据 API doesn't allow this (yet) ,所以为了解决这个问题,我使用 YouTubeService 实例的 GetYouTubeUserFeed 方法来获取我需要的所有视频条目的列表(无论它们是私有(private)的还是公共(public)的):

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)

希望这对遇到同样问题的人有帮助:)

关于python - 即使使用 gdata-python-client 使用所有者的帐户登录,获取私有(private) YouTube 视频时也会出现 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2991636/

相关文章:

python - 根据 Python 中的一组索引将列表拆分为子列表

python - 通过替换 iterrows 来加速 pandas 代码

php - 谷歌电子表格 API : memory exceeded

javascript - 嵌入带有侧边栏列表可见的 YouTube 播放列表插件

java - 通过 Intent 传递 Youtube 视频 ID

YouTube - Data API v3 无法使用 Google 服务帐户在我的网站上显示我的 YouTube channel 的私有(private)视频

python - 属性错误: 'module' object has no attribute 'tk'

python - 从文本中获取句子的正则表达式构造 - Python

python - 我的 Facebook 应用程序应该使用哪种授权

javascript - 在 Google Worksheet 中插入重音字符?