【发布时间】:2017-03-25 09:10:19
【问题描述】:
我正在尝试使用 php 中的 api 将事件发送到谷歌日历。但这总是有一些错误。无法理解下一步该怎么做。这是我的代码:
致命错误:/home/abcd/public_html/mouthworks/gplus-verifytoken-php-master/ 中的消息“调用 POST https://www.googleapis.com/calendar/v3/calendars/some_calendar@gmail.com/events?key={MY is here}: (401) Login Required”未捕获异常“Google_ServiceException” google-api-php-client/src/io/Google_REST.php:66 堆栈跟踪:#0 /home/abcd/public_html/mouthworks/gplus-verifytoken-php-master/google-api-php-client/src/io /Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /home/abcd/public_html/mouthworks/gplus-verifytoken-php-master/google-api-php-client/src/service/Google_ServiceResource .php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 /home/abcd/public_html/mouthworks/gplus-verifytoken-php-master/google-api-php-client/src/contrib/Google_CalendarService.php (494): Google_ServiceResource->__call('insert', Array) #3 /home/abcd/public_html/mouthworks/test.php(24): Google_EventsServiceResource->insert('some_calendar@g...', Object(Google_Even在 /home/abcd/public_html/mouthworks/gplus-verifytoken-php-maste r/google-api-php-client/src/io/Google_REST.php 第 66 行
require_once './gplus-verifytoken-php-master/
google-api-php-client/src/Google_Client.php';
require_once '
./gplus-verifytoken-php-master/
google-api-php- client/src/contrib/Google_CalendarService.php';
session_start();
ob_start();
$client = new Google_Client();
$client->setApplicationName('demo');
$client->
setClientId('client id');
$client->setClientSecret('secret');
$client->setRedirectUri('http://someurl.com');
$client->
setDeveloperKey('dev key');
$cal = new Google_CalendarService($client);
$event = new Google_Event();
$event->setSummary('Pi Day');
$event->setLocation('Math Classroom');
$start = new Google_EventDateTime();
$start->setDateTime('2016-11-14T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2016-11-14T10:25:00.000-05:00');
$event->setEnd($end);
// error is on this next line
$createdEvent =
$cal->events->insert('some_calendar@gmail.com',$event);
echo $createdEvent->id;
?>
【问题讨论】:
-
究竟是什么错误?
-
未捕获的异常“Google_ServiceException”和消息“调用 POST 某些 url 时出错
-
您能否复制准确的完整错误并将其放在您的问题中。
标签: php google-api google-calendar-api google-api-php-client