我已经成功地使用我找到的一些代码(zend和youtube api)将视频上传到youtube。
我修改了它以便可以通过代理服务器上传,但我遇到了麻烦。我已经评论了为实现代理支持而添加的行。代码如下:

<?php
        require_once 'Zend/Loader.php';
        Zend_Loader::loadClass('Zend_Gdata');
        Zend_Loader::loadClass('Zend_Gdata_YouTube');
        Zend_Loader::loadClass('Zend_Gdata_AuthSub');
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
        Zend_Loader::loadClass('Zend_Http_Client_Exception');  //added for proxy support
        Zend_Loader::loadClass('Zend_Http_Client');  //added for proxy support
        Zend_Loader::loadClass('Zend_Http_Client_Adapter_Proxy'); //added for proxy support
        Zend_Loader::loadClass('Zend_Gdata_App_HttpException');  //added for proxy support

    $config = array(
        'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
        'proxy_host' => 'MY_PROXY_IP',
        'proxy_port' => 8080,
        'proxy_user' => 'USER',
        'proxy_pass' => 'PASS'
    );   //added for proxy support

    $proxiedHttpClient = new Zend_Gdata_HttpClient('http://www.google.com/', $config); //added for proxy support
          try
          {
              $authenticationURL= 'https://www.google.com/accounts/ClientLogin';
              $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
               $username = 'YOUTUBE EMAIL ID',
               $password = 'YOUTUBE PASSWORD',
               $service = 'youtube',
               $client = $proxiedHttpClient,    //changed from "$client = null"
               $source = 'mysource',
               $loginToken = null,
               $loginCaptcha = null,
               $authenticationURL);
          }
          catch (Zend_Gdata_App_Exception $e)
          {
               $arry['data']['flag'] = false;
               $arry['data']['msg'] = 'Username or Password Invalid.';
               print_r(json_encode($arry));
               die();
          }
              $httpClient->setConfig($config);  //added for proxy support
              $developerKey='DEVELOPER KEY';
              $applicationId = 'not require';
              $clientId = 'not require';
              $yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
              $fileName = "FILENAME";
              $fileType = "video/mp4";
              $newEntry = new Zend_Gdata_YouTube_VideoEntry();
              $filesource = $yt->newMediaFileSource($fileName);
              $filesource->setContentType('video/mp4');
              $filesource->setSlug($fileName);
              $newEntry->setMediaSource($filesource);
              $newEntry->setVideoTitle("VIDEO TITLE");
              $newEntry->setVideoDescription("VIDEO DESCRIPTION HERE");
              $newEntry->setVideoCategory("VIDEO CATEGORY HERE");
              $newEntry->setVideoTags("VIDEO TAGS");
              try {
                    $newEntry = $yt->insertEntry($newEntry, 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads', 'Zend_Gdata_YouTube_VideoEntry');
                    $state = $newEntry->getVideoState();
                    if ($state)
                    {
                         $videourl = $newEntry->getVideoWatchPageUrl();
                             $arry['data']['flag'] = true;
                             $arry['data']['url'] = $videourl;
                             $arry['data']['msg'] = "Video Uploaded Successfully.";
                    }
                    else
                    {
                         $arry['data']['flag'] = false;
                         $arry['data']['msg'] = "Not able to retrieve the video status information yet. " ."Please try again later.\n";
                    }
              }
              catch (Zend_Gdata_App_Exception $e) {
                         $arry['data']['flag'] = false;
                         $arry['data']['msg'] = $e->getMessage();
              }
         echo "<pre>";
         print_r($arry);
         ?>

当我从命令行执行php时,它返回的消息是:
试图写入,但我们连接到了错误的代理服务器
我测试过的代理确实有效——事实上,如果我使用了一个损坏的代理,它只会说“用户名或密码无效”。使用有效的代理时,我只会收到上面的错误消息。
如有任何指导或解决办法,将不胜感激。

最佳答案

我也有同样的问题,我找到了一个对我有效的解决方案。我使用内置的curl适配器而不是代理适配器。
下面是我的例子…

$config = array(
    'adapter'    => 'Zend_Http_Client_Adapter_Curl',
    'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_PROXY => "proxy:port", CURLOPT_PROXYUSERPWD => "username:password")
);

10-07 19:32
查看更多