【问题标题】:Python Youtube API: Attempt to access Watch Later results in invalid URIPython Youtube API:尝试访问稍后观看会导致 URI 无效
【发布时间】:2013-03-05 23:48:39
【问题描述】:

相信已解决:Python API 仅支持 v1,而 watch later 是在 v2 中添加的。 SOURCE
解决方案:使用“实验性”API v3


我正在尝试使用 Youtube API 访问我的“稍后观看”播放列表。下面是我正在使用的代码。

import gdata.youtube
import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService()
yt_service.ssl = True
yt_service.developer_key = 'REDACTED'
yt_service.email = 'REDACTED'
yt_service.password = 'REDACTED'
yt_service.ProgrammaticLogin()

playlist_uri = 'https://gdata.youtube.com/feeds/api/users/default/watch_later?v=2'
playlist_video_feed = yt_service.GetYouTubePlaylistVideoFeed(uri=playlist_uri)
for playlist_video_entry in playlist_video_feed.entry:
  print playlist_video_entry.title.text

我收到以下错误。

Traceback (most recent call last):
  File "Youtube.py", line 21, in <module>
    playlist_video_feed = yt_service.GetYouTubePlaylistVideoFeed(uri=playlist_uri)
  File "/Library/Python/2.6/site-packages/gdata/youtube/service.py", line 393, in GetYouTubePlaylistVideoFeed
    uri, converter=gdata.youtube.YouTubePlaylistVideoFeedFromString)
  File "/Library/Python/2.6/site-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'}

似乎 URI https://gdata.youtube.com/feeds/api/users/default/watch_later?v=2 无效。然而,这是在谷歌文档中使用的。是我用错了,还是这里有其他问题?

此外,如果我将 URI 更改为 http://gdata.youtube.com/feeds/api/playlists/63F0C78739B09958,它会按预期工作。

【问题讨论】:

    标签: python youtube-api


    【解决方案1】:

    您应该检查您的身份验证。根据Retrieving and updating a user's 'Watch Later' playlist

    同样,只有在以下任一情况下,该链接才会出现在个人资料条目中 以下条件为真:

    您提交经过身份验证的请求以检索已登录用户的 自己的个人资料。

    watch_later 播放列表可供其用户公开使用 您正在检索的个人资料。

    如果您尝试,API 服务器将返回 40x HTTP 响应代码 检索 watch_later 播放列表,但上述条件均不成立 真的。

    由于满足第二个公开可用的条件,第二个链接很可能会起作用。我确实注意到您的示例中缺少的一件事是客户端 ID/来源:

    # A complete client login request
    yt_service.email = 'jo@gmail.com'
    yt_service.password = 'mypassword'
    yt_service.source = 'my-example-application'
    yt_service.developer_key = 'ABC123...'
    yt_service.client_id = 'my-example-application'
    yt_service.ProgrammaticLogin()
    

    您应该对此进行调查并确保您的身份验证正常进行。

    【讨论】:

    • 我发现了我的错误。显然 Python 库仅支持 API 的 v1,而稍后观看的播放列表是在 v2 中添加的。我不确定为什么谷歌已经离开 python 3 或 4 年没有任何 v2 支持。但它确实支持 v3。所以我想我会学习新的 API!尝试新语言是我的错。
    猜你喜欢
    • 2015-03-13
    • 2017-05-18
    • 2014-03-25
    • 2021-02-27
    • 2019-03-30
    • 2011-09-03
    • 2018-10-09
    • 2021-05-03
    • 2021-04-12
    相关资源
    最近更新 更多