未在服务帐户谷歌日历 api php 中创建环聊链接

Posted

技术标签:

【中文标题】未在服务帐户谷歌日历 api php 中创建环聊链接【英文标题】:Hangout link not created in service account google calendar api php 【发布时间】:2021-09-25 14:25:54 【问题描述】:

我无法通过以下代码从 GSUIT 服务帐户为 google 日历 api 生成会议链接。运行此功能时出现此错误

错误:

致命错误:未捕获的 Google\Service\Exception: "error": "errors": [ "domain": "global", "reason": "invalid", "message": "无效的会议类型值。” ], "code": 400, "message": "无效的会议类型值。" 在 D:\xampp\htdocs\projects\serviceaccount\vendor\google\apiclient\src\Http\REST.php:128 堆栈跟踪:#0 D:\xampp\htdocs\projects\serviceaccount\vendor\google\apiclient \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 D:\xampp\htdocs\ projects\serviceaccount\vendor\google\apiclient\src\Task\Runner.php(182): call_user_func_array(Array, Array) #3 D:\xampp\htdocs\projects\serviceaccount\vendor\google\apiclient\src\Http\ REST.php(66): Google\Task\Runner->run() #4 D:\xampp\htdocs\projects\serviceaccount\vendor\google\apiclient\src\Client.php 在 D:\xampp\htdocs\projects \serviceaccount\vendor\google\apiclient\src\Http\REST.php 在第 128 行

代码:

<pre>
$client = new Google\Client();
$client->setAuthConfig($jsonKey);
$client->setScopes(['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events','https://www.googleapis.com/auth/admin.reports.audit.readonly']);

$client->setSubject('myserviceemail@gserviceaccount.com');

$client->setAccessType('offline');

$cal_id = 'myemail@gsuit.com';

$calendarService = new Google\Service\Calendar($client);

$event = new Google\Service\Calendar\Event(array(
  'summary' => 'test link generate', //'Google Calendar ',
  'description' => 'Book Room', //'Book Room',
  'start' => array(
    'dateTime' => '2021-07-17T00:50:00+05:30',//'2018-08-16T14:30:00-00:00',
    'timeZone' => 'Asia/Kolkata',
  ),
  'end' => array(
    'dateTime' => '2021-07-17T00:55:00+05:30',//'2018-08-16T14:30:00-01:00',
    'timeZone' => 'Asia/Kolkata',
  ),
  'reminders' => array(
    'useDefault' => FALSE,
    'overrides' => array(
      array('method' => 'popup', 'minutes' => 10),
    ),
  ),
  'conferenceData' => array(
    'createRequest' => array(
      'conferenceSolutionKey' => array(
        'type' => 'hangoutsMeet'
      ),
        'requestId' => 'ADGGSH'. time()
    )
    )   
));

$createdEvent = $calendarService->events->insert($cal_id, $event, array('conferenceDataVersion' => 1)); 
</pre>

此代码出现以下错误,但不添加(ConferenceData 属性并设置 ConferenceDataVersion = 1)我可以在没有环聊链接的情况下创建活动

资源:

https://github.com/googleapis/google-api-php-client 作曲家需要 google/apiclient:^2.10

【问题讨论】:

【参考方案1】:

如果您要检查 Google Calendar API PHP reference documentation,Google_Service_Calendar_Events_Resource insert() 需要一个 Google_Service_Calendar_Event 对象。 conferenceData 应该是 Google_Service_Calendar_ConferenceData。

示例代码:

$conference = new \Google_Service_Calendar_ConferenceData();
$conferenceRequest = new \Google_Service_Calendar_CreateConferenceRequest();
$conferenceSolutionKey = new \Google_Service_Calendar_ConferenceSolutionKey();
$conferenceSolutionKey->setType("hangoutsMeet");
$conferenceRequest->setRequestId('ADGGSH'. time());
$conferenceRequest->setConferenceSolutionKey($conferenceSolutionKey);
$conference->setCreateRequest($conferenceRequest);

$event->setConferenceData($conference);

$event = new Google\Service\Calendar\Event(array(

  ......

  'conferenceData' => $conference   
));

【讨论】:

我尝试了你告诉我的方式......我之前已经在数组中传递了这些参数。这里的问题是,如果我设置 (conferenceDataVersion = 1) 参数,我会收到这个致命错误....如果我不设置它,则在没有满足链接的情况下创建事件 我没明白你的意思。在您的初始代码中,您在conferenceData 中传递了一个数组对象,这导致了致命错误Invalid conference type value。现在您的意思是,即使在尝试传递ConferenceData 对象的解决方案时,您仍然遇到相同的致命错误?您能否提供在实施建议的解决方案时使用的更新代码? 您能否确认您是否尝试使用服务帐户来模拟用户?或使用服务帐户模拟服务帐户? $client-&gt;setSubject('myserviceemail@gserviceaccount.com'); 因为此代码用于模拟,而您试图模拟的电子邮件似乎是一个服务帐户。你可以参考这里how to authenticate with service account 您需要模拟工作区用户才能创建 google meet 邀请,因为服务帐户没有这样的权限 顺便说一句,我注意到提供的答案中有错字。我将$conferenceRequest-&gt;setConferenceSolutionKey(conferenceSolutionKey); 更改为$conferenceRequest-&gt;setConferenceSolutionKey($conferenceSolutionKey);。我已经更新了答案。再次,请提供您最新的代码和遇到的错误,并请检查服务帐户冒充的用户【参考方案2】:
$client = new Google\Client();
$client->setAuthConfig($jsonKey);
$client->setScopes(['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events','https://www.googleapis.com/auth/admin.reports.audit.readonly']);

$client->setSubject('clientemail@gserviceaccount.com'); //This is my GSUIT service account(client email) created which is impersonating(linked to my personal GSUIT email)

$client->setAccessType('offline');

$cal_id = 'mypersonalemail@gsuit.com'; //The events created will appear on my GSUIT personal account

$calendarService = new Google\Service\Calendar($client);

$conference = new Google\Service\Calendar\ConferenceData();
 $conferenceRequest = new Google\Service\Calendar\CreateConferenceRequest();
 $conferenceSolutionKey = new Google\Service\Calendar\ConferenceSolutionKey();
 $conferenceSolutionKey->setType("hangoutsMeet");
 $conferenceRequest->setRequestId('ADGGSH'. time());
 $conferenceRequest->setConferenceSolutionKey($conferenceSolutionKey);
 $conference->setCreateRequest($conferenceRequest);

$event = new Google\Service\Calendar\Event(array(

  ......

  'conferenceData' => $conference   
));

$createdEvent = $calendarService->events->insert($cal_id, $event, array('conferenceDataVersion' => 1));

错误:

致命错误:未捕获的 Google\Service\Exception: "error": "errors": [ "domain": "global", "reason": "invalid", "message": "无效的会议类型值。” ], "code": 400, "message": "无效的会议类型值。"

【讨论】:

以上是关于未在服务帐户谷歌日历 api php 中创建环聊链接的主要内容,如果未能解决你的问题,请参考以下文章

使用 php 和服务帐户创建谷歌日历事件 - 身份验证问题

与会者在使用服务帐户、谷歌日历 API 创建活动时未收到会议邀请

Google OAuth 2.0 服务帐户 - 日历 API(PHP 客户端)

如何使用 android 使用日历 API 在谷歌日历上添加事件?

谷歌 api v3 日历 quickadd php

如何从单个谷歌帐户的多个谷歌日历中获取所有事件?