谷歌 api v3 日历 quickadd php
Posted
技术标签:
【中文标题】谷歌 api v3 日历 quickadd php【英文标题】:Google api v3 calandar quickadd php 【发布时间】:2021-05-19 16:01:25 【问题描述】:我正在尝试使用 google quickadd API 在我的 google 日历中创建事件。 这是我的代码:
require_once 'googleapi/vendor/autoload.php';
$client = new Google\Client();
$client->setApplicationName("Google Calendar API");
$client->setDeveloperKey("AIzaSyDdR3w2J59ZVVv_s7BopzNuteu1Bzo");
$client->setAuthConfig('googleapi/code_secret_client_62725432848-um1gbjoo7iqi1upvmv4niosddfte43.apps.googleusercontent.com.json');
$client->addScope("https://www.googleapis.com/auth/calendar.events");
$service = new Google_Service_Calendar($client);
// echo "<pre>";
// print_r($service);
// echo "</pre>";
$createdEvent = $service->events->quickAdd(
'myemail@gmail.com',
'Appointment at Somewhere on June 3rd 10am-10:25am'
);
echo $createdEvent->getId();
我不断收到以下错误。谁能告诉我为什么?
致命错误:未捕获的 Google\Service\Exception: "error": "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential . 见https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ "message": "Login Required.", "domain": "global", "reason": "required", "location": "Authorization", "locationType": "header" ], "status": "UNAUTHENTICATED" 在 C:\xampp\htdocs\google quick add\googleapi\src\Http\REST.php:128 堆栈跟踪:#0 C:\xampp\htdocs\ google 快速添加\googleapi\src\Http\REST.php(103): Google\Http\REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...' ) #1 [内部函数]: Google\Http\REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 C:\xampp\htdocs\google quick add\googleapi\src\Task\Runner.php(18 in C:\xampp\htdocs\google quick add\googleapi\src\Http\REST.php on line 128
【问题讨论】:
当您收到 401 异常时,我会检查凭据是否正常。 【参考方案1】:根据错误消息,您未获得授权。
these you can read about 401 HTTP code
And these you can see the example, right way to authorize your app
【讨论】:
以上是关于谷歌 api v3 日历 quickadd php的主要内容,如果未能解决你的问题,请参考以下文章
使用私有 URL 和 google api v3 共享 google 日历活动