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



我已经成功地上传视频到YouTube使用一些代码我发现(Zend与YouTube API)。我修改了它,这样我就可以通过代理服务器上传了,但我遇到了瓶颈。我已经注释了为实现代理支持而添加的行。下面是代码:

<?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适配器而不是Proxy适配器。

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

这段代码使用了关闭的GData API和已弃用的clientlogin

请更新到v3 API,这里是PHP的例子,让你开始

相关内容

  • 没有找到相关文章