Update & Delete file video youtube dengan PHP

Setelah kita berhasil upload video langsung ke youtube melalui website kita, selanjutnya bagaimana caranya untuk mengubah atau menghapus file yang bersangkutan. Langkah awalnya sama dengan postingan ane sebelumnya, bagaimana cara upload file video ke youtube. Konfigurasi awalnya pun juga sama, yg beda hanya bagian prosesnya saja.

Berikut adalah script untuk mengubah / update :

<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'youremail@mail.com',
              $password = 'yourpassword',
              $service = 'youtube',
              $client = null,
              $source = 'MazhtersSource', // untuk identifikasi aplikasi kita
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);


$developerKey = 'developerKey';
$applicationId = 'Test Upload Video';
$clientId = 'Test Upload Video Client';

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

$videoEntry = new Zend_Gdata_YouTube_VideoEntry();


$feed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/users/default/uploads');
foreach($feed as $entry) 
{
if($entry->getVideoId() == $video_id)
{
$videoEntry = $entry;
$videoEntry->setVideoTitle('ini title yg baru');
                $videoEntry->setVideoDescription('ini description yg baru');
                $putUrl = $videoEntry->getEditLink()->getHref();



                $yt->updateEntry($videoEntry, $putUrl);
                break;
}
}


echo "Update File Video Sukses";


?>

Sedangkan untuk menghapus / delete bisa menggunakan script berikut :


<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'youremail@mail.com',
              $password = 'yourpassword',
              $service = 'youtube',
              $client = null,
              $source = 'MazhtersSource', // untuk identifikasi aplikasi kita
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);

$developerKey = 'developerKey';
$applicationId = 'Test Upload Video';
$clientId = 'Test Upload Video Client';

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

$videoEntry = new Zend_Gdata_YouTube_VideoEntry();

$feed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/users/default/uploads');




$videoEntryToDelete = null;

foreach($feed as $entry) 
{
if ($entry->getVideoId() == $file_media)
{
$videoEntryToDelete = $entry;
                $yt->delete($videoEntryToDelete);
break;
}
}

echo "Delete File Video Sukses";


?>

Script2 diatas ane berasumsi bahwa file berhasil di update atau di delete, ente-ente bisa memodifikasi dengan menambahkan pesan error apabila file gagal terupdate / terdelete.

Tidak ada komentar:

Posting Komentar