【问题标题】:How do I upload a transcript to YouTube via the API?如何通过 API 将成绩单上传到 YouTube?
【发布时间】:2013-03-29 22:05:47
【问题描述】:

相关文档可在此处找到:https://developers.google.com/youtube/2.0/developers_guide_protocol_captions#Create_Caption_Track

我尝试了以下方法,但我只是收到一个深奥的“urllib2.HTTPError: HTTP Error 401: Unknown authentication header”

import gdata.youtube, gdata.youtube.service, urllib2
yt_service = gdata.youtube.service.YouTubeService()
yt_service.ClientLogin("username@gmail.com","password")
yt_service.ProgrammaticLogin()
auth = yt_service.current_token.get_token_string()
url = "https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/captions"
req = urllib2.Request(url, "Transcript", {'Content-Type': 'application/vnd.youtube.timedtext; charset=UTF-8', 'Content-Language:': 'en', 'Authorization': auth})
f = urllib2.urlopen(req)

【问题讨论】:

  • 该 URL 可能不应包含 %20HTTP/1.1
  • 你是对的。我刚刚试了一下,现在有一个新错误。我会相应地更新我的问题。
  • 在标题中使用'Authorization': 'Bearer '+auth 试试
  • 这次是“urllib2.HTTPError: HTTP Error 401: Token invalid”。所以看来我的请求格式正确,但我获取的授权密钥不正确。

标签: python youtube-api


【解决方案1】:

this blog post 中有大量信息,包括指向此sample Python script 的链接,用于上传字幕。

【讨论】:

  • 优秀的脚本——谢谢!我已经通过 API 上传了一些成绩单,它们在 my_videos_timedtext 页面上可见并正确解析,并且在页面上的播放器中可用,但在观看页面上不可用。知道为什么会发生这种情况或如何自动解决此问题吗?有关示例,请参见 youtube.com/watch?v=rrcFyORJdU8
猜你喜欢
  • 2019-11-12
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
  • 2014-09-27
  • 1970-01-01
相关资源
最近更新 更多