Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

send invitation using google calendar API in php

Am new in google calendar API, Written below code for sending invitation using google API.

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

$setsummary="setsummary";
$setLocation="setLocation";
$event = new Google_Event();
$event->setSummary($setsummary);
$event->setLocation($setLocation);
$start_date=date();
$start = new Google_EventDateTime();
$start->setDateTime($start_date);
$event->setStart($start);
$end_date=date();
$end = new Google_EventDateTime();
$end->setDateTime($end_date);
$event->setEnd($end);
$event->sendNotifications=true;
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('[email protected]');
$attendee2 = new Google_EventAttendee();
$attendee2->setEmail('[email protected]');
$attendees = array($attendee1,$attendee2);
$event->attendees = $attendees;      
$opt= array ("sendNotifications" => true);
$createdEvent = $cal->events->insert('********calendar id***********', $event, $opt);      
?>

but unfortunately it is not sending invitation. what I have missed in this? I just want to simply send invitation to [email protected]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do Not use Zend, Use Google php client lib . Below code is fully tested https://github.com/google/google-api-php-client

Go to console and create a project

https://console.developers.google.com

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//if (!isset($_SESSION['access_token']) {
   // session_start();
//}
// If you've used composer to include the library, remove the following line
// and make sure to follow the standard composer autoloading.
// https://getcomposer.org/doc/01-basic-usage.md#autoloading
require_once 'google-api-php-client/autoload.php';

$client_id = "client_id";
$client_email = 'client_email';
$private_key = file_get_contents('Project-e7659df9db10.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new Google_Auth_AssertionCredentials(
    $client_email,
    $scopes,
    $private_key
);

$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion();
}



//print_r($client->getAuth());
$service = new Google_Service_Calendar($client);

$event = new Google_Service_Calendar_Event();
$event->setSummary('Interview');
$event->setLocation('Dell');
$event->sendNotifications=true;

$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2015-02-14T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2015-02-14T11:00:00.000-07:00');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('[email protected]');


// ...
$attendees = array($attendee1,
                   // ...
                  );
$event->attendees = $attendees;
$sendNotifications = array('sendNotifications' => true);
$createdEvent = $service->events->insert('primary', $event, $sendNotifications);

echo $createdEvent->getId();
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...