【问题标题】:Attempting YouTube upload through Python API gives 'Developer key required for this operation' Error尝试通过 Python API 上传 YouTube 会出现“此操作所需的开发人员密钥”错误
【发布时间】:2012-12-30 08:03:09
【问题描述】:

我正在尝试使用与特定用户的凭据配对获得的开发者密钥将视频上传到 YouTube。在我看来,我的 YoutubeService 对象应该具有正确的开发人员凭据,但服务器返回 403:此操作所需的开发人员密钥。

import gdata
import gdata.youtube
import gdata.youtube.service
client_id = 'dummy-client'
developer_key = 'xxxxxxx......'
youtube_user = 'sampleuser@gmail.com'
youtube_password = 'passwordgoeshere'
yt_service = gdata.youtube.service.YouTubeService(client_id, developer_key)
yt_service.ssl = True
yt_service.developer_id = developer_key
yt_service.client_id = client_id
yt_service.email = youtube_user
yt_service.password = youtube_password
yt_service.source = client_id
yt_service.ProgrammaticLogin() #Successfully login with the developer key and the user's credentials

my_media_group = gdata.media.Group(
    title=gdata.media.Title(text='video.avi'),
    description=gdata.media.Description(description_type='plain', text='My Video'),
    keywords=gdata.media.Keywords(text=''),
    category=[gdata.media.Category(
    text='Autos',
    scheme='http://gdata.youtube.com/schemas/2007/categories.cat', label='Autos')],
    player=None,
    private=gdata.media.Private()
)
video_entry = gdata.youtube.YouTubeVideoEntry(media=my_media_group)
video_file_location = '/path/to/video.avi'

#Use the supposedly authenticated and developer_id associated YoutubeService object to upload the video
new_entry = yt_service.InsertVideoEntry(video_entry, video_file_location)

#Receive the following error:
#
#Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
#  File "/usr/lib/python2.7/dist-packages/gdata/youtube/service.py", line 661, in InsertVideoEntry
#    raise YouTubeError(e.args[0])
#gdata.youtube.service.YouTubeError: {'status': 403, 'body': 'Developer key required     for this operation', 'reason': 'Forbidden'}

【问题讨论】:

    标签: python youtube gdata


    【解决方案1】:

    您的开发者 ID 和开发者密钥是不同的东西。您需要将您的密钥(与您的帐户相关联,而不是与特定的注册应用程序相关联)放入 yt_service.developer_key

    【讨论】:

      猜你喜欢
      • 2012-12-30
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 2019-09-29
      • 2020-07-10
      • 1970-01-01
      • 2016-07-08
      • 2017-05-22
      相关资源
      最近更新 更多