1

I have created one application in YiiFramework which has two functionalities.

1. Login to google

For login to google, I have followed the tutorial on below website.

Tutorial : https://github.com/Nodge/yii-eauth
Tutorial Demo : http://nodge.ru/yii-eauth/demo/login

2  Get calendar using Zend_Gdata Library

Tutorial : http://www.bcits.co.in/googlecalendar/index.php/site/install
Tutorial Demo : http://www.bcits.co.in/googlecalendar/index.php/site/page?view=about

[1st Step] I get successfully login to my application using yii-eauth.
[2nd Step] when I need to use calendar, I am giving hard coded gmail Id and password.

I am accessing calendar in this way.

  <?php 
     $user = 'your gmail username';
     $pass ='your gmail password';
     Yii::app()->CALENDAR->login($user, $pass);
  ?>

login() in googlecalendar.php file.

 public function login($user, $pass) {

    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);// It uses hard-coded gmail/password to get login again
    $calenderlist = $this->outputCalendarList($client);
    $events = $this->outputCalendar($client);
    $calendardate = $this->outputCalendarByDateRange($client, $startDate = '2011-05-01', $endDate = '2011-06-01');
     .........
  }

Does Zend_Gdata library contain any function which automatically gets calendar of current user without again logging in(hard-coded here).

Stuck with this. Appreciate helps. Thanks

Alpesh Prajapati
  • 1,593
  • 2
  • 18
  • 38

1 Answers1

0

From my understanding, Zend_Gdata_ClientLogin sets some parameters for $client which is the object returned. See the following excerpt from that function:

if ($loginToken || $loginCaptcha) {
    if ($loginToken && $loginCaptcha) {
        $client->setParameterPost('logintoken', (string) $loginToken);
        $client->setParameterPost('logincaptcha', (string) $loginCaptcha);
    } else {
        require_once 'Zend/Gdata/App/AuthException.php';
        throw new Zend_Gdata_App_AuthException(
            'Please provide both a token ID and a user\'s response ' .
            'to the CAPTCHA challenge.');
    }
}

What you could do is store that token or that $client object (which is an instance of Zend_Gdata_HttpClient). Pretty much all of the Zend_Gdata components accept a $client argument.

Check out the __construct() method for Zend_Gdata_Calendar:

So anyway, you would want something similar to this logic (sorry I'm not familiar with Yii):

$client = Yii::app()->getClient();
if (!$client) {
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
    Yii::app()->setClient($client);
}

Of course, you would have to then define that getClient() method somehow.

Hope this helps!

Yes Barry
  • 9,514
  • 5
  • 50
  • 69
  • $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); would be the same as before. I dont want to pass username and password in getHttpClient(). hope you understand what i mean. – Alpesh Prajapati Nov 06 '12 at 09:00
  • You need to **store** the `$client` from where you _originally_ login and and _get_ it here. The `if` is a just-in-case sort of thing. Get it? – Yes Barry Nov 06 '12 at 09:03
  • 1
    ohhhh.. yes i get something now..need to work hard upon it :) ..thanks @mmmshuddup – Alpesh Prajapati Nov 06 '12 at 09:07