【问题标题】:watch History feed gdata python观看历史提要 gdata python
【发布时间】:2012-10-25 08:53:12
【问题描述】:

我正在尝试使用 python 从 YouTube 获取经过身份验证的用户的历史提要。 这是我的代码:

yt_service = gdata.youtube.service.YouTubeService()
def LogIn():
  login_name = raw_input('Email:')
  login_pass = getpass.getpass()
  try:
    yt_service.email = login_name
    yt_service.password = login_pass
    yt_service.ProgrammaticLogin()
  except:
    print 'False username or password. Unable to authenticate.'
    exit();

def GetHistoryFeed():
  uri = 'https://gdata.youtube.com/feeds/api/users/default/watch_history?v=2'
  feed = yt_service.GetYouTubeVideoFeed(uri)
  #PrintVideoFeed(yt_service.GetYouTubeVideoFeed(uri),'history')

LogIn()

GetHistoryFeed() 

它说 gdata.service.RequestError: {'status': 400, 'body': 'Invalid request URI', 'reason': 'Bad Request'} 。我知道我必须发出经过身份验证的 Get 请求,但我不知道如何。我究竟做错了什么 ?

编辑

我面临一个重大问题。程序与上面相同,但在密码行和uri = 'https://gdata.youtube.com/feeds/api/users/default/watch_history?v=2&key=%s'%DEVELOPER_KEY 下添加了yt_service.developer_key = DEVELOPER_KEY。我在 4 台 PC 上对其进行了测试,并且只有其中一台可以正常运行。我收到此错误:

File "/usr/local/lib/python2.6/dist-packages/gdata/youtube/service.py", line 186, in return self.Get(uri, converter=gdata.youtube.YouTubeVideoFeedFromString) File "/usr/local/lib/python2.6/dist-packages/gdata/service.py", line 1108, in Get 'reason': server_response.reason, 'body': result_body} gdata.service.RequestError: {'status': 400, 'body': 'Invalid request URI', 'reason': 'Bad Request'}

我使用 python 2.7 和 gdata python 2.0 。为什么一台PC执行它而其余的不执行?我能做些什么来解决它?请帮忙!

【问题讨论】:

  • 我将 gdata 版本从 2.0.17 更改为 2.0.16 并解决了问题。

标签: python youtube history gdata gdata-python-client


【解决方案1】:

当您尝试调用 youtube API 时,您首先需要注册一个新应用程序。参考——https://developers.google.com/youtube/2.0/developers_guide_protocol_authentication

访问http://code.google.com/apis/youtube/dashboard/ 注册您的应用程序并检索将为您生成的开发者密钥。

此后,每当您调用 youtube API 时,都应包含 key 查询参数。 (参考 - https://developers.google.com/youtube/2.0/developers_guide_protocol#Developer_Key

您的实例化 yt_service 将是:-

yt_service.developer_key = DEVELOPER_KEY

DEVELOPER_KEY 是您在新注册的应用程序仪表板 (http://code.google.com/apis/youtube/dashboard/) 上看到的那个。

如果没有这个DEVELOPER_KEY,google youtube 将无法知道您的 python 脚本是否实际上是一个公认的应用程序,并具有适当的访问权限。

【讨论】:

  • 我按照你说的做了,但我一直收到这个错误。我得到了一个开发者密钥,在 ProgrammaticLogin() 之前将其添加到 yt_service 实例中,并将 GetYouTubeVideoFeed 发送到 uri = 'gdata.youtube.com/feeds/api/users/default/…' %DEVELOPER_KEY ,但没有任何改变。
  • 仍然无法在我的机器上工作。它适用于其他机器,但不适用于我的机器。这是为什么 ?我使用 python 2.6.5 和 youtube API v2.0 。
猜你喜欢
  • 1970-01-01
  • 2016-08-15
  • 2017-10-31
  • 1970-01-01
  • 2022-08-05
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
  • 2020-09-27
相关资源
最近更新 更多