Search code examples
phpzend-frameworkgdata-api

login the browser into google with php (zend gdata)


I was using the private share link for viewing a calendar inside my users personal page, but now google decided to change things https://www.google.com/support/calendar/bin/answer.py?answer=1631300

Say I have a user's password and username. I can login to a Google account and add events or stuff using Zend Framework, but how can I login to Google and make the browser logged in (inject a cookie or something, as if the user went to gmail, he is already logged in).

This way the user would see his own calendar and won't be getting any warnings.

UPDATE

how can i show the calendar(even read only would be ok too) in an iframe if i have user/password of his gmail(or google) account


Solution

  • You have to make sure that the user has either shared the calendar or made it public. Google is trying to harden their security. The method you were using allowed you to access a user's private calendars. This is clearly undesirable behavior. The Google Data Protocol api supports several authentication methods. The paage HERE is meant to help you choose which is right for your application. The api docs reccomend using oauth to authenticate, and the site http://oauth.net/ offers several libraries for accessing the API from PHP. OpenID is also a supported option, as well as a hybrid which is meant to streamline the process by taking advantage of both OAuth and OpenID.

    As far as displaying the calendar in an IFrame, just create an html page that Retrieves the atom feed for your calendar and displays the events as html. As it is XML any XML handling method you like will work (i.e. XSLT, simpleXML, etc.,) Then Use the url of this page as the source attribute of your iframe.

    Here is an example using the ZEND gata library:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title>Example List of calendar contents</title>
      </head>
      <body>
        <?php
          // load library
          require_once 'Zend/Loader.php';
          Zend_Loader::loadClass('Zend_Gdata');
          Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
          Zend_Loader::loadClass('Zend_Gdata_Calendar');
          Zend_Loader::loadClass('Zend_Http_Client');
    
          // create authenticated HTTP client for Calendar service
          $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
          $user = "username@gmail.com";
          $pass = "pass";
          $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
          $gcal = new Zend_Gdata_Calendar($client);
    
          // generate query to get event list
          $query = $gcal->newEventQuery();
          $query->setUser('default');
          $query->setVisibility('private');
          $query->setProjection('basic');
    
          // get and parse calendar feed
          // print output
          try { $feed = $gcal->getCalendarEventFeed($query); } 
          catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getResponse(); }
        ?>
        <h1><?php echo $feed->title; ?></h1>
        <p><?php echo $feed->totalResults; ?> event(s) found.<p/>
        <ol>
          <?php        
            foreach ($feed as $event) 
            {
              echo "<li>\n";
              echo "<h2>" . stripslashes($event->title) . "</h2>\n";
              echo stripslashes($event->summary) . " <br/>\n";
              echo "</li>\n";
            }
            echo "</ul>";
          ?>
        </ol>
    
      </body>
    </html> 
    

    The URL of this file is the source of your IFrame.
    Good luck and happy coding.