1

这让我发疯了。我真的很讨厌发布问题,但“来了”。

我能够使用 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);
}
4

1 回答 1

0

我在堆栈跟踪中注意到了这一点:

Zend_Gdata_HttpClient->setAdapter(Object(__PHP_Incomplete_Class))

注意它是如何说它正在将一个__PHP_Incomplete_Class对象传递给setAdapter.

我的猜测是,当您从数据库中提取对象并对其进行反序列化时,您正在反序列化的类不会被加载,这就是它成为__PHP_Incomplete_Class对象的原因。

在尝试从数据库中反序列化 HTTP 客户端之前,请尝试添加此代码:

else
{
    Zend_Loader_Autoloader::autoload('Zend_Gdata_HttpClient');
    $httpClient = unserialize($auth['http_client']);
}

通过预加载类,当你调用反序列化时,它应该作为一个Zend_Gdata_HttpClient而不是不完整的类出来。

如果这不起作用,请尝试加载Zend_Http_Client,因为这是Zend_Gdata_HttpClient扩展的内容。

编辑:也尝试使用较新的自动加载器;代替:

require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata_HttpClient');

和:

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance(); // this sets up the ZF autoloader

Zend_Loader_Autoloader::autoload('Zend_Gdata_HttpClient');
于 2012-07-27T23:05:00.710 回答