需要帮助将带有谷歌日历 API v2 的 php 脚本迁移到 v3


Need Help Migrating php script with google calendar api v2 to v3

嗨,我试图将我的 php 脚本 v2 API 迁移到 v3,但我不知道该怎么办......

我阅读了Google日历API版本3.0迁移指南,但不知道是否可以与zend_gdata一起使用或该怎么做。

    
    <?php
    } else {
      // load classes
      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');
      
      // connect to service
	  $title = $_POST['ACTUACION']."/".$_POST['NOMBRE']."/".$_POST['TELEFONO'];
	  $title = strtoupper($title);
	  $where = $_POST['MUNICIPIO']."/".$_POST['DIRECCION']; 
	  $where = strtoupper($where);
	  $description = $_POST['CAPTACION']."/".$_POST['ESTADO']."/".$_POST['PROCEDENCIA'].$_POST['PROCEDENCIA2']."/".$_POST['REFPROCEDENCIA'];
	  $description = strtoupper($description);
      $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
	  $user = $_POST['email'];
      $pass = $_POST['pass'];
      $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
      $gcal = new Zend_Gdata_Calendar($client);
      
      // validate input
      if (empty($title)) {
        die('ERROR: Missing title');
      } 
      
      if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])) {
        die('ERROR: Invalid start date/time');        
      }
      if (!checkdate($_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy'])) {
        die('ERROR: Invalid start date/time');      
	  }
      if (($_POST['sdate_hh']) < ($_POST['edate_hh'])){
		  die('ERROR: Hora de fin incorrecta');
	  }
	  
		$horas_inicio = $_POST['hora_inicio'];
		list ($sdate_hh, $sdate_ii) = split('[:]', $horas_inicio);
		$horas_fin = $_POST['hora_fin'];
		list ($edate_hh, $edate_ii) = split('[:]', $horas_fin);
      
      $title = htmlentities($title);
      $start = date(DATE_ATOM, mktime($sdate_hh,$sdate_ii,
       0, $_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy']));
      $end = date(DATE_ATOM, mktime($edate_hh, $edate_ii, 
       0, $_POST['sdate_mm'], $_POST['sdate_dd'], $_POST['sdate_yy']));
      // construct event object
      // save to server      
      try {
        $event = $gcal->newEventEntry();        
        $event->title = $gcal->newTitle($title);
		$event->where = array($gcal->newWhere($where));
        $event->content = $gcal->newContent($description);       
        $when = $gcal->newWhen();
        $when->startTime = $start;
        $when->endTime = $end;
        $event->when = array($when);        
        $gcal->insertEvent($event);   
      } catch (Zend_Gdata_App_Exception $e) {
        echo "Error: " . $e->getResponse();
      }
      echo 'CITA CREADA!</br>';
 	  
	  echo "<form method='"post'" action='"calendar.php'">";
	  $user = $_POST['email']; $pass = $_POST['pass'];
      echo "<input name='"email'" type='"hidden'" value=".$user."'"/>";
      echo "<input name='"pass'" type='"hidden'" value=".$pass."'"/>";
	  echo "<input  type='"submit'" value='"INTRODUCIR MAS CITAS'" />";
	  echo "</form>";
	  echo '<a href="https://www.google.com/calendar" target="_blank">Acceder al Calendario</a>';  	    
    }
    ?>
       

这是我的代码,有了这个,我插入日历的所有事件,我如何修改使用 google 日历 v3 键?

提前感谢,对不起我的英语。

应首先按照此处设置 V3 的第一个应用步骤进行操作:https://developers.google.com/google-apps/calendar/firstapp

然后继续从"下载"部分下载 PHP 客户端库:https://developers.google.com/google-apps/calendar/downloads

最后,按照插入引用中的示例进行操作:https://developers.google.com/google-apps/calendar/v3/reference/events/insert 但将所有与"事件"相关的类型替换为"Google_Service_Calendar_Event",因为较新的客户端库更改了名称。

我终于有了这些东西,开始自己工作并进行大量搜索。我以前也使用过Zend。Daimto.com 有一个非常好的网站,您可以在其中看到一堆教程。以下是使用代码形式添加事件的代码 Daimto.com 并添加用于在正文中添加事件的代码。请记住,您还需要将服务电子邮件添加到Google日历的共享中!

<?php
session_start();        
require_once './google-api-php-client/src/Google/Client.php';
require_once './google-api-php-client/src/Google/Service/Calendar.php';     
$client_id = '6846057_YOUR_CLIENT_ID_HERE_pg3q8r6.apps.googleusercontent.com';
$Email_address = '68460_YOUR_SERVICE_EMAIL_HERE_developer.gserviceaccount.com';  
$key_file_location = '_KEY_FILE_LOCATION_HERE_8.p12';       
$client = new Google_Client();      
$client->setApplicationName("_APP_NAME_HERE_");
$key = file_get_contents($key_file_location);    
// seproate additional scopes with a comma   
$scopes ="https://www.googleapis.com/auth/calendar";    
$cred = new Google_Auth_AssertionCredentials(    
  $Email_address,       
    array($scopes),     
    $key         
    );      
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {        
   $client->getAuth()->refreshTokenWithAssertion($cred);       
}       
$service = new Google_Service_Calendar($client);    
?>
<html><body>
<?php
    //
    $event = new Google_Service_Calendar_Event();
    $event->setSummary('Event 2');
    $event->setLocation('Somewhere');
    $start = new Google_Service_Calendar_EventDateTime();
    $start->setDateTime('2015-06-22T19:00:00.000+01:00');
    $start->setTimeZone('Europe/London');
    $event->setStart($start);
    $end = new Google_Service_Calendar_EventDateTime();
    $end->setDateTime('2015-06-22T19:25:00.000+01:00');
    $end->setTimeZone('Europe/London');
    $event->setEnd($end);
    //
     $calendar_id = "nm_GOOGLE_CAL_ID_HERE_@group.calendar.google.com";
    //
    $new_event = null;
    //
    try {
        $new_event = $service->events->insert($calendar_id, $event);
        //
        $new_event_id= $new_event->getId();
    } catch (Google_ServiceException $e) {
        syslog(LOG_ERR, $e->getMessage());
    }
    //
    $event = $service->events->get($calendar_id, $new_event->getId());
    //
    if ($event != null) {
        echo "Inserted:";
        echo "EventID=".$event->getId();
        echo "Summary=".$event->getSummary();
        echo "Status=".$event->getStatus();
    }    
?>