这让我发疯了。我真的很讨厌发布问题,但“来了”。
我能够使用 Zend Gdata API for You Tube 上传视频。“一个视频”...
自从我收到此错误以来:
Fatal error: Uncaught exception 'Zend_Http_Client_Exception' with message
'Passed adapter is not a HTTP connection adapter'
in ../pathtoapp/Zend/Http/Client.php:926
Stack trace:
#0 ../pathtoapp/Zend/library/Zend/Gdata/HttpClient.php(275): Zend_Http_Client->setAdapter(Object(__PHP_Incomplete_Class))
#1 ../pathtoapp/Zend/library/Zend/Gdata/App.php(692): Zend_Gdata_HttpClient->setAdapter(Object(__PHP_Incomplete_Class))
#2 ../pathtoapp/Zend/library/Zend/Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'http://uploads....', Array, Object(Zend_Gdata_MediaMimeStream), 'multipart/relat...', NULL)
#3 ../pathtoapp/Zend/library/Zend/Gdata/App.php(910): Zend_Gdata->performHttpRequest('POST', 'http://uploads....', Array, Object(Zend_Gdata_MediaMimeStream), 'multipart/relat...')
#4 /home/spotya/public_html/devblogpost/php/Zend/library/Zend/Gdata/App.php(985): Zend_Gdata_App-> in ../pathtoapp/Zend/library/Zend/Http/Client.php on line 926
我发现的类似帖子已经解决了这个问题,但他们的解决方案对我不起作用。
我的代码:
error_reporting(E_ALL);
require_once('Zend/Loader.php');
require_once('../../includes/defines.php');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');
$client = new Zend_Gdata_HttpClient();
$developerKey = '';
$applicationID = '';
$clientID = '';
$sql = "SELECT * FROM `you_tube_credentials` WHERE `user_id` = '1'";
$auth = $db->FetchAssoc($db->Query($sql));
if($auth['id'] == '') // If Auth Key not stored in DB get one
{
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = '',
$password = '',
$service = 'youtube',
$client = null,
$source = 'My Videos', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL
);
$httpClient_ser = serialize($httpClient);
$sql = "INSERT INTO `you_tube_credentials` (`user_id`,`user_name`,`password`,`application`,`developer_key`,`http_client`)
VALUES
(1,'social@spotya.com','XXXXXXX','Spotya Videos','".$db->Escape($developerKey)."','".$db->Escape($httpClient_ser)."')";
$db->Query($sql);
header('location: youtube.php');
}
else
{
$httpClient = unserialize($auth['http_client']);
}
$sql = "SELECT * FROM `video_cue` WHERE `posted` < 4 AND `post_datetime` < '".date('Y-m-d H:i:m')."'";
$result = $db->Query($sql);
while($row = $db->FetchAssoc($result))
{
$transactionid = time();
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube($httpClient,"Spotya Videos",$clientID,$developerKey);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource(realpath('/pathtovideo/video_auto_upload/'.$row['file_name']));
//$filesource = $yt->newMediaFileSource(realpath('Wildlife.mp4'));
$filesource->setContentType('video/mp4');
// set slug header
$filesource->setSlug($row['file_name']);
// add the filesource to the video entry
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle($row['title']);
$myVideoEntry->setVideoDescription($row['description']);
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory('Education');
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags($row['tags']);
// upload URI for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
// try to upload the video, catching a Zend_Gdata_App_HttpException,
// if available, or just a regular Zend_Gdata_App_Exception otherwise
$sql = "INSERT INTO `video_post_log` (`transactionid`,`sent`,`status`)
VALUES ('".$transactionid."',
'".$db->Escape(serialize($myVideoEntry))."',
'Initialized')";
$db->Query($sql);
try
{
$result = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
}
catch (Zend_Gdata_App_HttpException $httpException)
{
$result = $httpException->getRawResponseBody();
}
catch (Zend_Gdata_App_Exception $e)
{
$result = $e->getMessage();
}
if(is_array($result) == true || is_object($result) == true)
{
if(strpos($result,'xml') === false)
{
$result = serialize($result);
}
}
$sql = "UPDATE `video_post_log` SET `result`= '".$db->Escape($result)."',`status` = 'Complete' WHERE `transactionid` = '".$transactionid."'";
$db->Query($sql);
$sql = "UPDATE `video_cue` SET `posted`=`posted`+1 WHERE `file_name` = '".$row['file_name']."'";
$db->Query($sql);
}