将视频作为不公开内容上传到YouTube

时间:2011-06-06 17:34:30

标签: php zend-framework youtube

因此,我可以使用PHP客户端库将视频上传到YouTube(直接上传)并将其设置为私有,但是可以将其设置为不公开吗?

2 个答案:

答案 0 :(得分:5)

您必须将此代码用作请求的XML元素的子代:

<yt:accessControl action="list" permission="denied"/>

如果您无法手动添加(通常使用zend),您可以使用此代码添加相应的zend条目:

//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); 

希望这会有所帮助:D

答案 1 :(得分:0)

使用API​​ ver 2和ZEND GDATA执行此操作。 如果您查看$ videoEntry的内容,您会注意到 $ _extensionElements和$ _extensionArributes。 所以从扩展的VideoEntry类向后看 你会发现抽象类Zend_Gdata_App_Base 它有一个函数setExtensionElements(array)。 所以只做别人说的创建accesControlElement 并将其传递给该函数.. 它的工作原理。

$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 />";

}
相关问题