简体   繁体   中英

PHP using Zend for Google Calendar not generating webpage

I am working on the tutorial on IBM.com for using the Zend framework to work with the Google Calendar API. I literally copied a chunk of code from the tutorial and tried to use it, but it does not seem to be working. My php file includes the following:

<!--Some HTML is above here-->
  <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"; //replace with my username
    $pass = "pass"; //replace with my password
    $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 {
      echo "<!--this comment is seen-->\n";
      $feed = $gcal->getCalendarEventFeed($query);
      echo "<!--this comment is not seen-->\n";
    } catch (Zend_Gdata_App_Exception $e) {
      //this doesn't happen.
      echo "Error: " . $e->getResponse();
    }
    ?>
    <h1><?php echo $feed->title; ?></h1>
    <?php echo $feed->totalResults; ?> event(s) found.
    <p/>
    <ol>
  </body>

Literally the only changes I made to this code is replacing the username and password with my own email address and password. When the code execution reaches the statement in the try block, it seems to fail, but is not caught in the catch block, even when I change it to catch any exception, not just Zend_Gdata_App_Exception . The generated page source clearly shows that the PHP is crashing, though:

  <!--Some HTML is above here-->
  <body>
  <!--this comment is seen-->

with nothing after that. I am learning PHP on the fly here, so any help would be extremely appreciated!

<?php

**$path = 'ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);**

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

...

and you should download the ZendGdata/library like they explain here https://developers.google.com/google-apps/calendar/v1/developers_guide_php that is the official google calendar api Developer's Guide. The code you are using is deprecated though. I'm still using it but they suggest you switch over to google calendar API v3, you can find the documentation for that, on the same page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM