php - 使用 Zend 上传到 YouTube - 通过代理

标签 php zend-framework proxy youtube-api

我已经使用找到的一些代码(Zend with 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 时,它返回的消息是:

Trying to write but we are connected to the wrong proxy server

我一直在测试的代理绝对有效——事实上,如果我使用损坏的代理,它只会显示“用户名或密码无效”。我只在使用工作代理时收到上面的错误消息。

任何指导或解决方案将不胜感激。

最佳答案

我遇到了同样的问题,我找到了适合我的解决方案。我使用内置的 cURL 适配器而不是代理适配器。

请看下面我的例子...

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

关于php - 使用 Zend 上传到 YouTube - 通过代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24647979/

相关文章:

java - Spring JDK 动态代理和 CGLIB - 实现细节

javascript - ExtJS:如何从任何其他代理 Access Ajax 请求的值?

php - 意外的T_FUNCTION

php - 如何在 swift json 请求中传递数组

php - 基于触发器和存储过程更新汇总表

javascript - Jquery/Zend 切换元素禁用不起作用

android - 在 Android Studio 中设置 Http 代理

php - 如何通过ssh连接php应用程序和远程mysql数据库

php - LEFT JOIN 还是只选择额外的表?

php - Paypal - Zend_Http_Client_Adapter_Curl - 如何打开 CURLOPT_VERBOSE