To access a Google Data API through a proxy connection you will need to use the
Zend_Http_Client_Adapter_Proxy
proxy adapter. In the snippet below, we are going to access our private Google Documents feed from the
DocumentsList API through a proxy connection:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_App_HttpException');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Docs');
Zend_Loader::loadClass('Zend_Http_Client_Exception');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Http_Client_Adapter_Proxy');
// Configure the proxy connection
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
'proxy_host' => 'your.proxy.server.net',
'proxy_port' => 3128
);
// We are setting http://www.google.com:443 as the initial URL since we need to perform
// ClientLogin authentication first.
$proxiedHttpClient = new Zend_Http_Client('http://www.google.com:443', $config);
$username = 'foo@example.com';
$password = 'barbaz';
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
// Try to perform the ClientLogin authentication using our proxy client.
// If there is an error, we exit since it doesn't make sense to go on. You may want to
// modify this according to the needs of your application.
try {
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service,
$proxiedHttpClient);
} catch (Zend_Gdata_App_HttpException $httpException) {
exit("An error occurred trying to connect to the proxy server\n" .
$httpException->getMessage() . "\n");
}
// If that worked, proceed and retrieve the documents feed.
// Remember to set your application ID.
$docsClient = new Zend_Gdata_Docs($httpClient, $yourApplicationId);
$feed = $docsClient->getDocumentListFeed();
?>