gpt4 book ai didi

google-calendar-api - 在 php 中使用谷歌日历 API 发送邀请

转载 作者:行者123 更新时间:2023-12-04 15:11:36 25 4
gpt4 key购买 nike

在谷歌日历 API 中是新的,
写在下面使用谷歌 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('xyz@gmail.com');
$attendee2 = new Google_EventAttendee();
$attendee2->setEmail('xyzx@gmail.com');
$attendees = array($attendee1,$attendee2);
$event->attendees = $attendees;
$opt= array ("sendNotifications" => true);
$createdEvent = $cal->events->insert('********calendar id***********', $event, $opt);
?>

但不幸的是它没有发送邀请。
我错过了什么?
我只想简单地向 xyz@gmail.com 发送邀请

最佳答案

不要使用 Zend,使用 Google php client lib 。以下代码经过全面测试 https://github.com/google/google-api-php-client

转到控制台并创建一个项目

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('some@someone.com');


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

echo $createdEvent->getId();
?>

关于google-calendar-api - 在 php 中使用谷歌日历 API 发送邀请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21523094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com