Youtube API get default title

Links for php scripts

Moderators: macek, egami, gesf

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

Youtube API get default title

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

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

//include Zend Gdata Libs 
//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= ''; 
$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, 

$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->SetVideoTags('cars, funny');

$tokenHandlerUrl = '';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];

$uploadUrl = "$yt_user/uploads";
// place to redirect user after upload
$nextUrl = '';

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



Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest