Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Youtube API get default title

Links for php scripts

Moderators: macek, egami, gesf

Youtube API get default title

Postby qenibas » Sat Feb 18, 2012 7:23 am

Hi..
I got a problem with my youtube uploader.
I need the user to be able to write their own title, so all the video's aren't called the same thing.
I've tried with $_POST['title'], and other kinds of code, but nothing seems to help, and most of them makes an error.

Anyone who knows how to do it?
Here's my code:

Code: Select all
<?php 
 
//include Zend Gdata Libs 
require_once("Zend/Gdata/ClientLogin.php"); 
require_once("Zend/Gdata/HttpClient.php"); 
require_once("Zend/Gdata/YouTube.php"); 
require_once("Zend/Gdata/App/MediaFileSource.php"); 
require_once("Zend/Gdata/App/HttpException.php"); 
require_once('Zend/Uri/Http.php'); 
 
//yt account info 
$yt_user = '**'; //youtube username or gmail account 
$yt_pw = '**'; //account password 
$yt_source = '**'; //name of application (can be anything) 
 
//video path 
$video_url = '/full/path/to/video'; 
 
//yt dev key 
$yt_api_key = '**'; //your youtube developer key 
 
//login in to YT 
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin'; 
$httpClient = Zend_Gdata_ClientLogin::getHttpClient( 
                                          $username = $yt_user, 
                                          $password = $yt_pw, 
                                          $service = 'youtube', 
                                          $client = null, 
                                          $source = $yt_source, // a short string identifying your application 
                                          $loginToken = null, 
                                          $loginCaptcha = null, 
                                          $authenticationURL); 


 
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key); 
 
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 
 
$filesource = $yt->newMediaFileSource($video_url); 
 
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$myVideoEntry->setVideoTitle('The Movie');
$myVideoEntry->setVideoDescription('My test Movie');
$myVideoEntry->setVideoCategory('Autos');
$myVideoEntry->setVideoPrivate();
$myVideoEntry->SetVideoTags('cars, funny');


$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];


$uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads";
// place to redirect user after upload
$nextUrl = 'http://sabinequardon.dk';

// build the form
$form = '<form id="youtube_upload" action="'. $postUrl .'?nexturl='. $nextUrl .
        '" method="post" enctype="multipart/form-data" target="uploader">'.
        '<input id="title" name="video_title" type="text"/>'.
        '<input id="file_upload" name="file_upload" type="file"/>'.
        '<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
        '<input value="Upload Video File" type="submit" />'.
        '</form><iframe id="uploader" name="uploader" style="display: none; width: 500px; height: 200px; border:1px solid #000;"></iframe>
';

echo $form; 

try {
    $control = $myVideoEntry->getControl();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e->getMessage();
}

if ($control instanceof Zend_Gdata_App_Extension_Control) {
    if ($control->getDraft() != null &&
        $control->getDraft()->getText() == 'yes') {
        $state = $myVideoEntry->getVideoState();

        if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
            print 'Upload status: '
                  . $state->getName()
                  .' '.  $state->getText();
        } else {
            print 'Not able to retrieve the video status information'
                  .' yet. ' . "Please try again shortly.\n";
        }
    }
}

?>



Thanks.
qenibas
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Feb 18, 2012 7:16 am

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron