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

2022-08-30 22:28:26

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


答案 1

必须将此代码用作请求的 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


答案 2

这样做..使用 API 版本 2 和 ZEND GDATA。如果您查看$videoEntry的内容,则会注意到$ _extensionElements和$ _extensionArributes。因此,从VideoEntry的扩展类向后看,你会发现抽象类Zend_Gdata_App_Base,它有一个函数setExtensionElements(array)。因此,只需按照其他人所说的创建accecontrolElement并将其传递给该函数。它的工作原理。

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

}

推荐