I had the installation of a system with the YouTube v2 data API, which would allow the user to upload the video directly to the MY YouTube account through the form on my site (I understand the consequences of this, please keep in mind that I just give a simple description of what the tool did ) I still could not figure out how to configure the same system using the v3 API now that v2 is deprecated. One more note, I would like to do this without sending the user to the OAuth page, since I do not need to access their YouTube account.
Here is a small version of the PHP code that made this work for v2:
<?php
if ($_GET['op'] == "yt") {
if ($_GET['status'] == "200") {
} else {
}
} 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";
}
?>