Jump to content

Upload to YouTube with PHP?


schilly

Recommended Posts

Has anyone had any success doing this?

 

I'm not sure if I should try to write this myself or use some kind of framework. I found the Zend Gdata framework (http://framework.zend.com/manual/en/zend.gdata.html) and tried it out but I kept getting error: Warning: include_once() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/share/pear')

 

I'm assuming it needs to find PEAR which I don't have installed but no where in the Zend docs does it say that it requires PEAR so I'm a little confused. I've never used any of the Zend frameworks so I have no idea if it needs PEAR or not.

 

Anyone have any other methods for doing this?

 

Thx.

Link to comment
https://forums.phpfreaks.com/topic/212904-upload-to-youtube-with-php/
Share on other sites

Ok got this working finally. Good example here: http://code.google.com/apis/youtube/2.0/developers_guide_php.html

 

Here's my code:

<?php
error_reporting(E_ALL);

//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 = 'username or gmail address';
$yt_pw = 'pw';
$yt_source = 'name for your application';

//yt dev key
$yt_api_key = 'api-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('absolute/path/to/video');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('mytestmovie.mov');

$myVideoEntry->setMediaSource($filesource);

$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');

// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');

// Upload URI for the currently authenticated user

$uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads";

// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor just a regular Zend_Gdata_App_Exception

try {
    $newEntry = $yt->insertEntry($myVideoEntry,
                                 $uploadUrl,
                                 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
    echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e->getMessage();
}

echo "<pre>" . var_dump($newEntry) . "</pre>";

echo 'end';

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.