Esempio n. 1
0
 private function getHttpClient($userEmail, $password, $proxyHost = null, $proxyPort = null, $tries = 3)
 {
     $authenticationURL = Zend_Gdata_YouTube::CLIENTLOGIN_URL;
     $service = Zend_Gdata_YouTube::AUTH_SERVICE_NAME;
     if (isset($userEmail) && isset($password)) {
         try {
             if (isset($proxyHost) && isset($proxyPort)) {
                 $httpConfig = array('adapter' => 'Zend_Gdata_HttpAdapterStreamingProxy', 'proxy_host' => $proxyHost, 'proxy_port' => $proxyPort, 'maxredirects' => 5, 'timeout' => 120, 'keepalive' => true);
                 //$httpConfig = array ('adapter' => 'Zend_Http_Client_Adapter_Proxy', 'proxy_host' => $proxy->proxy, 'proxy_port' => $proxy->port,'maxredirects' => 10, 'timeout' => 120, 'keepalive' => true );
                 try {
                     // creates a proxied client to use for authentication
                     $clientp = new Zend_Gdata_HttpClient($authenticationURL, $httpConfig);
                     // To turn cookie stickiness on, set a Cookie Jar
                     $clientp->setCookieJar();
                     // authenticate
                     //$httpClient = Zend_Gdata_ClientLogin::getHttpClient ( $userEmail, $password, $service, $clientp );
                     $httpClient = Zend_Gdata_ClientLogin::getHttpClient($userEmail, $password, $service, $clientp, 'WePromoteThis.com', null, null, $authenticationURL);
                     // set the proxy information back into the client
                     // necessary due to http://framework.zend.com/issues/browse/ZF-1920
                     $httpClient->setConfig($httpConfig);
                     //echo ("Using Proxy: $proxyHost port: $proxyPort<br>");
                 } catch (Zend_Gdata_App_HttpException $e) {
                     //var_dump ( $e );
                     //echo ("Error Using Proxy: $proxyHost  port: $proxyPort<br>" . $e->getMessage () . "<br>");
                     $httpClient = Zend_Gdata_ClientLogin::getHttpClient($userEmail, $password, $service, null, 'WePromoteThis.com', null, null, $authenticationURL);
                 }
             } else {
                 //echo ("Not Using Proxy");
                 $httpClient = Zend_Gdata_ClientLogin::getHttpClient($userEmail, $password, $service, null, 'WePromoteThis.com', null, null, $authenticationURL);
             }
         } catch (Exception $e) {
             //echo ("Error getting Youtube HttpClient: " . $e->getMessage () . "<br>");
             $this->httpException = $e->getMessage();
         }
     } else {
         //echo ("Credentials missing. Username: $userEmail | Password length: " . strlen ( $password ) . " <br>");
     }
     if (!isset($httpClient) && $tries > 0) {
         sleep(30);
         $httpClient = $this->getHttpClient($userEmail, $password, $proxyHost, $proxyPort, --$tries);
     }
     return $httpClient;
 }