PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating a ClientLogin authenticated Http Client

The process of creating an authenticated HTTP client using the ClientLogin mechanism is to call the static function Zend_Gdata_ClientLogin::getHttpClient() and pass the Google account credentials in plain text. The return value of this function is an object of class Zend_Http_Client.

The optional third parameter is the name of the Google Data service. For instance, this can be 'cl' for Google Calendar. The default is "xapi", which is recognized by Google Data servers as a generic service name.

The optional fourth parameter is an instance of Zend_Http_Client. This allows you to set options in the client, such as proxy server settings. If you pass NULL for this parameter, a generic Zend_Http_Client object is created.

The optional fifth parameter is a short string that Google Data servers use to identify the client application for logging purposes. By default this is string "Zend-ZendFramework";

The optional sixth parameter is a string ID for a CAPTCHA™ challenge that has been issued by the server. It is only necessary when logging in after receiving a CAPTCHA™ challenge from a previous login attempt.

The optional seventh parameter is a user's response to a CAPTCHA™ challenge that has been issued by the server. It is only necessary when logging in after receiving a CAPTCHA™ challenge from a previous login attempt.

Below is an example of PHP code for a web application to acquire authentication to use the Google Calendar service and create a Zend_Gdata client object using that authenticated Zend_Http_Client.

<?php
// Enter your Google account credentials
$email 'johndoe@gmail.com';
$passwd 'xxxxxxxx';
try {
   
$client Zend_Gdata_ClientLogin::getHttpClient($email$passwd'cl');
} catch (
Zend_Gdata_App_CaptchaRequiredException $cre) {
    echo 
'URL of CAPTCHA image: ' $cre->getCaptchaUrl() . "\n";
    echo 
'Token ID: ' $cre->getCaptchaToken() . "\n";
} catch (
Zend_Gdata_App_AuthException $ae) {
   echo 
'Problem authenticating: ' $ae->exception() . "\n";
}

$cal = new Zend_Gdata_Calendar($client);

Zend Framework