Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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 Youtube上传到自己的帐户_Python_Youtube_Youtube Api_Google Api - Fatal编程技术网

Python Youtube上传到自己的帐户

Python Youtube上传到自己的帐户,python,youtube,youtube-api,google-api,Python,Youtube,Youtube Api,Google Api,我正试图使用API将视频上传到我的Youtube账户,但我找不到一个简单的方法。我看到的所有方法都要求我在浏览器中使用oAuth进行身份验证 我只想使用用户名和密码或开发密钥或类似的方式将视频从脚本上传到一个帐户,而不必经历疯狂的、过于复杂的身份验证方法。脚本将在专用in环境中运行,因此安全性不受关注。请尝试: (如果您使用django) 一旦用户授权上传,您就可以获得一个刷新令牌。 因此,您可以为“”范围手动获取该令牌表单,保存它并使用脚本定期获取访问令牌。然后,您可以插入该访问令牌进行上载

我正试图使用API将视频上传到我的Youtube账户,但我找不到一个简单的方法。我看到的所有方法都要求我在浏览器中使用oAuth进行身份验证

我只想使用用户名和密码或开发密钥或类似的方式将视频从脚本上传到一个帐户,而不必经历疯狂的、过于复杂的身份验证方法。脚本将在专用in环境中运行,因此安全性不受关注。

请尝试:

(如果您使用django)

一旦用户授权上传,您就可以获得一个刷新令牌。 因此,您可以为“”范围手动获取该令牌表单,保存它并使用脚本定期获取访问令牌。然后,您可以插入该访问令牌进行上载


总而言之,浏览器交互只需要一次,您可以通过Playway手动保存令牌。

使用ZEND,有一种方法,但google不赞成这种方法:客户端登录

即使您用pyton标记您的问题,我认为这个PHP示例也可以帮助您给出您的想法

<?php
/*First time, first: start the session and calls Zend Library. 
Remember that ZEND path must be in your include_path directory*/

session_start();

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

$authenticationURL= 'https://accounts.google.com/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser@gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'My super duper application',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);

 //Now, create an Zend Youtube Objetc
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);


  // create a new video object
  $video = new Zend_Gdata_YouTube_VideoEntry();
  $video ->setVideoTitle('Test video');
  $video ->setVideoDescription('This is a test video');
  $video ->setVideoCategory('News'); // The category must be a valid YouTube category

//Will get an one-time upload URL and a one-time token

  $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
  $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
  $tokenValue = $tokenArray['token']; //Very important token, it will send on an hidden input in your form
  $postUrl = $tokenArray['url']; //This is a very importan URL

  // place to redirect user after upload
  $nextUrl = 'http://your-site.com/after-upload-page'; //this address must be registered on your google dev

  // build the form using the $posturl and the $tokenValue
  echo '<form action="'. $postUrl .'?nexturl='. $nextUrl .
          '" method="post" enctype="multipart/form-data">'.
          '<input name="file" type="file"/>'.
          '<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
          '<input value="Upload Video File" type="submit" />'.
          '</form>';   
?>

我真的希望这会有帮助。
“祝你今天愉快

尝试YouTube直接上传Lite。设置起来真的很容易


“添加YouTube Direct Lite与向现有网页添加iframe HTML标记一样简单。不需要配置或部署服务器端代码,但我们建议您签出自己的YouTube Direct Lite HTML/CSS/JavaScript副本,并将其托管在现有web服务器上。”
youtube upload
是一个非常好的工具,您可以充分利用它。这将向您展示如何使用
Youtube upload

在Youtube频道上载视频。安全性始终是一个问题。但除此之外,我无法想象pyhton没有用于oAuth的库。我不建议将其用于新的应用程序,因为它使用旧的API(v2,而我们目前有v3),并且使用ClientLogin,而不是YouTube真正希望您现在使用的OAuth 2.0。也就是说,它仍然有效,我只是不建议它。