未在服务帐户谷歌日历 api php

时间:2021-07-16 20:16:09

标签: php google-calendar-api

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

错误:

<块引用>

致命错误:未捕获的 Google\Service\Exception: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Invalid Conference Type value .” } ], "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\项目\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

2 个答案:

答案 0 :(得分:0)

如果您检查 Google Calendar API PHP reference documentationGoogle_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   
));

答案 1 :(得分:0)

$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": "Invalid Conference Type value .” } ], "code": 400, "message": "无效的会议类型值。" } }