Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用相同的设置访问另一个日历-谷歌日历API PHP_Php_Google Api_Google Calendar Api_Google Api Php Client - Fatal编程技术网

使用相同的设置访问另一个日历-谷歌日历API PHP

使用相同的设置访问另一个日历-谷歌日历API PHP,php,google-api,google-calendar-api,google-api-php-client,Php,Google Api,Google Calendar Api,Google Api Php Client,我使用谷歌日历PHP API从日历中获取事件 一切都与初始日历一起工作,但现在我尝试使用相同的设置从另一个日历(相同的Google帐户)接收事件 日志中有以下错误: PHP致命错误:在/www/apache/domains/www.domain.ee/htdocs/wp content/themes/THEME/booking/vendor/Google/apiclient/src/Google/Http/REST.PHP:79中出现未捕获异常“Google\u Service\u except

我使用谷歌日历PHP API从日历中获取事件

一切都与初始日历一起工作,但现在我尝试使用相同的设置从另一个日历(相同的Google帐户)接收事件

日志中有以下错误:

PHP致命错误:在/www/apache/domains/www.domain.ee/htdocs/wp content/themes/THEME/booking/vendor/Google/apiclient/src/Google/Http/REST.PHP:79中出现未捕获异常“Google\u Service\u exception”,并显示消息“调用GET时出错:(404)找不到”

下面是代码:(我唯一更改的是
$calendarId


将相同的数据插入Google API资源管理器将返回我正在查找的事件。

从Google日历API中的处理API错误中,您有时得到的数据表示找不到指定的资源。其他可能的原因是请求的资源(具有提供的ID)从未存在,或者访问用户无法访问的日历

这里建议的操作是使用


基于此,此问题的另一个原因是,当使用访问私人日历时,如果您拥有包含这些日历的域,则需要执行权限委派,或者需要将私人日历与服务帐户的电子邮件地址共享。

就是这样,我忘了将日历与服务的电子邮件共享!非常感谢你@SilverRingvee即使具有适当的凭据,是否每个域用户都需要共享日历才能访问该服务?
require_once 'vendor/autoload.php';

$client_email = 'name@name.iam.gserviceaccount.com';
$private_key = file_get_contents('name.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new Google_Auth_AssertionCredentials(
    $client_email,
    $scopes,
    $private_key
);

$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion();
}

$service = new Google_Service_Calendar($client);

// Print the next 999 events on the user's calendar.
$calendarId = 'calendar_id@group.calendar.google.com';
$optParams = array(
  'maxResults' => 999,
  'orderBy' => 'startTime',
  'singleEvents' => TRUE,
  'timeZone' => 'Europe/Tallinn',
  'timeMin' => '2016-09-19T00:01:00Z',
  'timeMax' => '2018-07-17T00:00:00Z',
);
$results = $service->events->listEvents($calendarId, $optParams);