php - Google Calendar API:无法通过 PHP 中的服务帐户访问获取新创建的活动的 Google Meet 链接
问题描述
我无法让它工作,一直在查看其他几个相关的问题和答案,我认为问题出在我为此使用服务帐户这一事实中。情况是:
- 我有一个 Google 服务帐户和一个 Google 日历 ID(使用服务密钥访问)
- 我可以毫无问题地在日历中创建一个新事件。
- 当我还尝试获取 Google Meet 链接时,我收到错误消息:“会议类型值无效”
这是我的代码:
$client = new Google_Client();
$client->setAuthConfig(xxx);
$client->setScopes("https://www.googleapis.com/auth/calendar");
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
"description" => "Test",
"start" => array(
"dateTime" => "2021-09-01T09:00",
"timeZone" => "Europe/Brussels",
),
"end" => array(
"dateTime" => "2021-09-01T10:00",
"timeZone" => "Europe/Brussels",
)
));
// add google meet link
$solution_key = new Google_Service_Calendar_ConferenceSolutionKey();
$solution_key->setType("hangoutsMeet");
$confrequest = new Google_Service_Calendar_CreateConferenceRequest();
$confrequest->setRequestId("X".time());
$confrequest->setConferenceSolutionKey($solution_key);
$confdata = new Google_Service_Calendar_ConferenceData();
$confdata->setCreateRequest($confrequest);
$event->setConferenceData($confdata);
$event = $service->events->insert($google_calendar_id, $event, array('conferenceDataVersion' => 1));
如果没有参数“array('conferenceDataVersion' => 1)”,则正在创建事件。我几乎可以肯定它与访问权限有关,但我不知道再去哪里看......
解决方案
“无效的会议类型值”
表示您发送的是会议类型
$solution_key->setType("hangoutsMeet");
您正在使用的日历不允许使用哪个
$google_calendar_id,
尝试运行calendar.get并发送您尝试使用的日历 ID。
要求:
$service->calendar->get($google_calendar_id)
回复:
{
"kind": "calendar#calendar",
"etag": "\"j3g2ipQvsbvz0_YlxYi3Ml2Fd7A\"",
"id": "xxxxx@gmail.com",
"summary": "Linda Lawton ",
"description": "test",
"timeZone": "Europe/Copenhagen",
"conferenceProperties": {
"allowedConferenceSolutionTypes": [
"hangoutsMeet"
]
}
}
响应中的 allowedConferenceSolutionTypes 将告诉您该日历允许使用哪种类型。
就服务帐户而言,只需确保您设置了域范围的委派,并且您正在委派给域上的用户,这不应该是任何问题。
$client->setSubject($user_to_impersonate);
推荐阅读
- amazon-redshift - 转换为字符串以浮动后尾随 0 小数
- python - Python NumPy 在 where 等运算符后添加 []
- python-3.x - 需要从 pyspark 中的数据框中删除重复的列
- python - Firestore 中是否有“最小”功能
- sql - 当用户是多个组的成员时,如何根据用户组过滤 APEX 网格中的数据?
- r - 对数刻度 y 轴上的两个数据集和带有标题的辅助轴上的另一个数据集
- python - 如何计算我的单词列表在数据框行中出现的总和?
- android - PagedListAdapter 重新加载没有占位符的数据
- excel - 用户窗体没有正确关闭
- python - 如何使用 python 将多个工作簿与图表结合起来