2014-07-09 27 views
3

我已經使用我發現的一些代碼(YouTube與YouTube的Zend)成功上傳視頻到YouTube。 我修改了它,以便我可以通過代理服務器上傳,但我碰到了一堵磚牆。我評論了我爲了實現代理支持而添加的行。下面是代碼:使用Zend上傳到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,消息就還給是:

試圖寫,但我們連接到錯誤的代理服務器

我一直在測試的代理服務器絕對有效 - 事實上,如果我使用了一個破損的代理服務器,它只是說「用戶名或密碼無效」。在使用工作代理時,我只會收到上述錯誤消息。

任何指導或解決方案將不勝感激。

回答

0

我有同樣的問題,我找到了解決方案,爲我工作。我使用內置的cURL適配器而不是代理適配器。

見下面我舉的例子...

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