Upload video to YouTube as unlisted
So, I am able to upload a video to YouTube (direct upload) using the PHP client library an开发者_运维知识库d set it to private, but is it possible to set it as unlisted?
You must use this code as a child of the XML element of the request:
<yt:accessControl action="list" permission="denied"/>
If you can't add it manually (usually using zend) you may use this code to add the corresponding zend entry:
//Creates an extension to Zend Framework
$element = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
//Adds the corresponding XML child/attribute
$element->extensionAttributes = array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied'));
//Adds this extension to you video entry where "$myVideo" is your video to be uploaded
$myVideo->extensionElements = array($element);
Hope this helps :D
Do that.. with API ver 2 and ZEND GDATA. If you look at the content of a $videoEntry you will note a $_extensionElements and $_extensionArributes. So looking backwards from the extended class of VideoEntry you will found the abstract class Zend_Gdata_App_Base and it has a function setExtensionElements(array). So only do what others say to create the accesControlElement and pass it to that function.. And IT WORKS.
$videoEntry = $yt->getFullVideoEntry($id);
if ($videoEntry->getEditLink() !== null) {
echo "<b>Video is editable by current user</b><br />";
$putUrl = $videoEntry->getEditLink()->getHref();
//set video to unlisted
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
// here is the hidden function
// it´s on a abstract class Zend/Gdata/App/Base/Base.php
// Where ZEND/Gdata/Youtube/VideoEntry.php extends
$videoEntry->setExtensionElements(array($accessControlElement));
$yt->updateEntry($videoEntry, $putUrl);
}else{
echo "<b>EL Video no es editable por este usuario</b><br />";
}
精彩评论