我知道有很多关于这个问题的请求;但他们似乎都没有回答我的问题。为了自动生成 Google 日历约会,包括自动生成相应的 Google Meet Link,我做了以下工作:
JSON
,比方说access.json
.
putenv('GOOGLE_APPLICATION_CREDENTIALS=my/key/data/directoy/access.json');
$client = new Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Calendar::CALENDAR);
// Set up the Calendar API service
$service = new Google_Service_Calendar($client);
// Create a new event on Google Calendar
$event = new Google_Service_Calendar_Event(
[
'summary' => 'Meeting',
'start' => [
'dateTime' => '2023-04-07T10:00:00-07:00',
// Replace with your desired start time
'timeZone' => 'America/Los_Angeles',
// Replace with your desired timezone
],
'end' => [
'dateTime' => '2023-04-07T11:00:00-07:00',
// Replace with your desired end time
'timeZone' => 'America/Los_Angeles',
// Replace with your desired timezone
]
]
);
// Set the event's conference data to use Google Meet
$conferenceRequest = new Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId(uniqid());
$solution_key = new Google_Service_Calendar_ConferenceSolutionKey();
$solution_key->setType("hangoutsMeet");
$conferenceRequest->setConferenceSolutionKey($solution_key);
$conference = new Google_Service_Calendar_ConferenceData();
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
// Insert the event into the user's calendar
$calendarId = 'myCalendarsID';
$event = $service->events->insert(
$calendarId,
$event,
[ 'conferenceDataVersion' => 1 ]
);
var_dump($event);
// Retrieve the generated Google Meet link from the event's conference data
$meetLink = $event->getHangoutLink();
我真的尝试听从本论坛所有其他帖子关于这个问题的建议;但没有任何作用,我现在得到一个
400 Bad Request
错误,无论我设置的type
(hangoutsMeet
或其他什么),说Invalid conference type value.
。我错过了什么?我遇到过这个;这可能是特定于库的,最好在不使用库的情况下实现原始 HTTP REST API 调用?
尝试使用您的代码来设置 conf 数据,如下所示,使用适用于 PHP 的 Google API 客户端生成带有自动 Google Meet 链接的 Google 日历约会
<?php
// Include the Google API client library
require __DIR__ . '/vendor/autoload.php';
// Set the path to your Google Cloud service account key file
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_key.json');
// Create a new Google API client instance
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Calendar::CALENDAR);
// Set up the Google Calendar API service
$service = new Google_Service_Calendar($client);
// Set the start and end times of the appointment
$startDateTime = new DateTime('2023-04-07T10:00:00-07:00', new DateTimeZone('America/Los_Angeles'));
$endDateTime = new DateTime('2023-04-07T11:00:00-07:00', new DateTimeZone('America/Los_Angeles'));
// Create a new Google Calendar event with the specified start and end times
$event = new Google_Service_Calendar_Event([
'summary' => 'Meeting',
'start' => [
'dateTime' => $startDateTime->format(DateTime::RFC3339),
'timeZone' => $startDateTime->getTimezone()->getName(),
],
'end' => [
'dateTime' => $endDateTime->format(DateTime::RFC3339),
'timeZone' => $endDateTime->getTimezone()->getName(),
],
]);
// Set the event's conference data to use Google Meet
$conferenceRequest = new Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId(uniqid());
$conferenceSolutionKey = new Google_Service_Calendar_ConferenceSolutionKey();
$conferenceSolutionKey->setType('hangoutsMeet');
$conferenceRequest->setConferenceSolutionKey($conferenceSolutionKey);
$conferenceData = new Google_Service_Calendar_ConferenceData();
$conferenceData->setCreateRequest($conferenceRequest);
$event->setConferenceData($conferenceData);
// Insert the event into the user's calendar
$calendarId = 'primary'; // Change this to the calendar ID you want to use
$event = $service->events->insert($calendarId, $event, ['conferenceDataVersion' => 1]);
// Retrieve the generated Google Meet link from the event's conference data
$meetLink = $event->getHangoutLink();
// Output the generated Google Meet link
echo 'Google Meet link: ' . $meetLink;
注:
/path/to/service_account_key.json
$calendarId
值。您必须通过
composer require google/apiclient
安装Dipendency ..