Using the PHP Client Library through a Proxy connection


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();

?>

18 comments:

o_Ojack said...

I have exactly the same code, but I am getting the following error message: "Fatal error: Call to undefined method Zend_Http_Client::setClientLoginToken() in C:\xampp\php\ZendGdata\library\Zend\Gdata\ClientLogin.php on line 155"

Which is strange because Client.Login.php is the framework's code. Please advice, I have been stucked on this for a few days :(

Eric (Google) said...

Try using Zend_Gdata_HttpClient instead of Zend_Http_Client

ferdy182 said...

What if proxy requires user and password to access through it?

Thanks

Eric (Google) said...

Can't you pass the proxy_user/proxy_pass as a config option to the adaptor?

http://framework.zend.com/manual/en/zend.http.client.adapters.html

zzeng said...

Great,
I am searching the php code using Proxy.
My question is that must we use the Zend library?
are there any other options?
thanks.
http://net-kane.com

Mike from Devon said...

I am trying to use this code but am getting the same error as o_Ojack. Eric's suggestion to use Zend_Gdata_HttpClient instead of Zend_Http_Client is not clear and generates other errors.

Can you post corrected script with you suggestion in place, please?

Thanks,

Mike

Mike from Devon said...

I managed to get the following working:

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_Gdata_HttpClient('http://www.google.com:443', $config); /*******changed line *******/

$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();

google said...

Uploading, getting file list, deleting docs from the App store works here with php, using the Zend libarary, with simple username/password. Yes, this may be less secure, but for my purposes password login is sufficient at least for starts.
livesexmelbourne strippers

google said...

I include GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); the starting point for any OAuth Code I get a NoClassDefFoundError error.

Penis PumpSydney Escort

Yahoo said...

Once you enter PeekShows.com you will have immediate access to Free Live Webcams. Cam to cam with hot nude porn models right now! Free live porno sex videos, in real time. Its Free Porn and Free Live Sex for the common man! PeekShows Girls are waiting right now and 24/7 to watch you and engage in cam to cam sex with you! PeekShows Cam Models want to watch you stroke your cock just for them on web cam to cam, while they play with their pussys and please you in the hottest sexchat on earth! Join now and claim your free lifetime membership to PeekShows.com! Only you decide when it is time to purchase tokens on PeekShows.com for your own sneak peek, tokens which you will use for hot 1on1 private action with your favorite model! Sexting your favorite models are waiting to please you, don't make them wait for a quick peek. ;)
free cam to camred sexy lingerie

Yahoo said...

London Escorts

We aim to be the leading London escort directory providing you with the hottest London escorts, English escorts, UK escorts, British escorts. Our london escort and Uk escort girls are all porn stars, xxx stars, xxx amateurs, porn amateurs and naughty teen girls that want to please you in London, England.
how to grow your penisLondon Escorts

google said...

and therefore there is a much lower probability of macular degeneration for our eyes. Spinach is generally eaten as a side dish. However, it can be a delicious salad or omelet ingredient.
chat sexLas Vegas Escort

google said...

Trophozoite
As a trophozoite, it moves around to find bacteria it can feed on. And it grows the fastest at a temperature of 42°C. When it comes in contact with the human brain, it starts destroying the tissues and digests red blood cells and white blood cells.

discount sexy lingerieSydney Escort

google said...

This compression hampers the normal functioning of these nerves in the body. Signals sent to and from the brain may turn abnormal because their transmission fails at the point of compression.
Vegas Escortseffects of salvia

kosovohp said...

socks5 | socks proxy | proxy free | proxy
socks proxy | socks5 | proxy | proxy free

Consultant Afaceri said...

Same thing at Consultanta-Plan-Afaceri.eu

Hiphop4Cash said...

Which is strange because Client.Login.php is the framework's code. Please advice, I have been stucked on this for a few days :(
Elektriske dildoerGold Coast Escorts

kosovohp said...

Girl Xinh | Hot Girl | Cute Girl | Sexy Girl | Hot Girl Asian
Hot Girl | Lexi Belle | Sexy Girl | Cute Girl | Hot Asian Girl | Leah Dizon | Hot Girl Asian | Girl Xinh
socks proxy | socks5 | proxy free |proxy list