Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试通过Python API上传YouTube会导致';此操作需要开发人员密钥';错误_Python_Youtube_Gdata - Fatal编程技术网

尝试通过Python API上传YouTube会导致';此操作需要开发人员密钥';错误

尝试通过Python API上传YouTube会导致';此操作需要开发人员密钥';错误,python,youtube,gdata,Python,Youtube,Gdata,我正在尝试使用开发人员密钥将视频上载到YouTube,该密钥与特定用户的凭据一起获得。在我看来,我的YoutubeService对象应该具有正确的开发人员凭据,但服务器返回时会显示此操作所需的403:developer密钥 import gdata import gdata.youtube import gdata.youtube.service client_id = 'dummy-client' developer_key = 'xxxxxxx......' youtube_user = '

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

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'}
导入gdata
导入gdata.youtube
导入gdata.youtube.service
客户机\u id='虚拟客户机'
开发者密钥='xxxxxxx……'
youtube\u用户界面sampleuser@gmail.com'
youtube_password='PasswordGoesher'
yt_service=gdata.youtube.service.youtube服务(客户端id,开发者密钥)
yt_service.ssl=True
yt_service.developer_id=developer_key
yt_service.client_id=客户端_id
yt_service.email=youtube_用户
yt_service.password=youtube_密码
yt_service.source=客户端id
yt_service.programmaticologin()#使用开发人员密钥和用户凭据成功登录
my_media_group=gdata.media.group(
title=gdata.media.title(text='video.avi'),
description=gdata.media.description(description_type='plain',text='My Video'),
关键词=gdata.media.keywords(文本=“”),
category=[gdata.media.category(
text='Autos',
策划http://gdata.youtube.com/schemas/2007/categories.cat“,label='Autos')],
玩家=无,
private=gdata.media.private()
)
video\u entry=gdata.youtube.YouTubeVideoEntry(media=my\u media\u group)
视频文件位置='/path/to/video.avi'
#使用假定已验证且开发者id关联的YouTube服务对象上载视频
new\u entry=yt\u service.InsertVideoEntry(视频项目、视频文件位置)
#收到以下错误:
#
#回溯(最近一次呼叫最后一次):
#文件“”,第1行,在
#文件“/usr/lib/python2.7/dist packages/gdata/youtube/service.py”,第661行,插入视频条目
#提高YouTubeError(例如参数[0])
#gdata.youtube.service.YouTubeError:{'status':403,'body':'Developer key required for this operation','reason':'probled'}

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