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

时间:2022-10-14 21:49:16

So, I am able to upload a video to YouTube (direct upload) using the PHP client library and set it to private, but is it possible to set it as unlisted?

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

2 个解决方案

#1


5  

You must use this code as a child of the XML element of the request:

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

<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:

如果你不能手动添加它(通常使用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); 

Hope this helps :D

希望这会有所帮助:D

#2


0  

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.

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

}

#1


5  

You must use this code as a child of the XML element of the request:

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

<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:

如果你不能手动添加它(通常使用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); 

Hope this helps :D

希望这会有所帮助:D

#2


0  

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.

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

}