YouTube Data API V3直接表格上传
-
21-12-2019 - |
题
我有一个系统设置,带有YouTube数据API V2,可以让用户将视频直接上传到我的 YouTube帐户,通过我的网站上的表格(我了解这个含义,请保持请记住,我只是给出了工具所做的事情的描述。到目前为止,我已经无法弄清楚如何使用V3 API设置同一系统,现在v2被推荐。另一个快速注意,我希望能够在不发送用户到OAuth页面的情况下这样做,因为我无需访问它们 YouTube帐户。
以下是v2:
的PHP代码的瘦版本的PHP代码版本<?php
if ($_GET['op'] == "yt") {
if ($_GET['status'] == "200") {
// video upload was successful, $_GET['id'] contains the YouTube video ID for the upload
} else {
// video upload failed
}
} else {
require_once("Zend/Loader.php");
Zend_Loader::loadClass("Zend_Gdata_ClientLogin");
Zend_Loader::loadClass("Zend_Gdata_YouTube");
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = "YOUTUBE_USERNAME",
$password = "YOUTUBE_PASSWORD",
$service = "youtube",
$client = null,
$source = "My Video Upload Bla Bla Bla",
$loginToken = null,
$loginCaptcha = null,
"https://www.google.com/accounts/ClientLogin"
);
$yt = new Zend_Gdata_YouTube($httpClient, "My Video Upload Bla Bla Bla", "My Video Upload Bla Bla Bla", "YOUTUBE_DEVELOPER_KEY");
$yt->setMajorProtocolVersion(2);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle("Video Title");
$myVideoEntry->setVideoDescription("Video Description");
$myVideoEntry->setVideoCategory("People");
$accessControlElement = new Zend_Gdata_App_Extension_Element("yt:accessControl", "yt", "http://gdata.youtube.com/schemas/2007", "");
$accessControlElement->setExtensionAttributes(array(
array("namespaceUri" => "", "name" => "action", "value" => "list"),
array("namespaceUri" => "", "name" => "permission", "value" => "denied")
));
$myVideoEntry->setExtensionElements(array($accessControlElement));
$tokenArray = $yt->getFormUploadToken($myVideoEntry, "http://gdata.youtube.com/action/GetUploadToken");
$nextUrl = urlencode("http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?op=yt");
print "<form action=\"{$tokenArray['url']}?nexturl={$nextUrl}\" method=\"POST\" enctype=\"multipart/form-data\">\n";
print " <input name=\"file\" type=\"file\" />\n";
print " <input name=\"token\" type=\"hidden\" value=\"{$tokenArray['token']}\" />\n";
print " <input value=\"Upload Video File\" type=\"submit\" />\n";
print "</form>\n";
}
?>
. 解决方案
我找到了一篇帮助我的优秀文章:
http://jasonwritescode.blogspot.com/2013/09 / YouTube-浏览器基于上传 - with.html
如果您使用本文来帮助您同样的问题,请指出一些事情。卷曲调用 http://gdata.youtube.com/action/getuploadtoken 需要是 https 不是http和form action=“{post_url}}?next= {{next_url}}需要action=”{post_url}}? nexturel ={{next_url}}。
不隶属于 StackOverflow