服务帐户无法查看与其明确共享的节目日历

I am trying to access all organisation calendars from a Service Account but calendars/events are not viewable - even though they have been explicitly shared with the Service Account.

I have followed the delegation instructions. and the Drive example for instantiating a service (converted to the Calendar service).

I was surprised that the Service Account cannot automatically have Administrator-level access to calendars but even explicit sharing is not delivering the access needed.

If anyone spots something I have missed or misunderstood, then please let me know. Any help would be appreciated.

Mike

set_include_path(get_include_path() . PATH_SEPARATOR . 'google-api-php-    client-master/src');
require_once 'google-api-php-client-master/src/Google/autoload.php'; // or wherever autoload.php is located

require_once "google-api-php-client/src/Google/Client.php";
require_once "google-api-php-client/src/Google/Service/Calendar.php";
require_once "google-api-php-client/src/Google/Service/Oauth2.php";

define('CALENDAR_SCOPE', 'https://www.googleapis.com/auth/calendar.readonly');
define('SERVICE_ACCOUNT_EMAIL', 'DEV_EMAIL@developer.gserviceaccount.com');
define('SERVICE_ACCOUNT_PKCS12_FILE_PATH', 'P12_FILE.p12');

function buildService($userEmail) {
  $key = file_get_contents(SERVICE_ACCOUNT_PKCS12_FILE_PATH);
  $auth = new Google_Auth_AssertionCredentials(
      SERVICE_ACCOUNT_EMAIL,
      array(CALENDAR_SCOPE),
      $key);
  $auth->sub = $userEmail;
  $client = new Google_Client();
  $client->setAssertionCredentials($auth);
  return new Google_Service_Calendar($client);
}

$v_calendarId_primary = "USER_CHOSEN@email.com";

$service = buildService($v_calendarId_primary);

$calendarId = 'primary';
$optParams = array(
  'maxResults' => 10,
  'orderBy' => 'startTime',
  'singleEvents' => TRUE,
  'timeMin' => date('c'),
);

$results = $service->events->listEvents($v_calendarId_primary, $optParams);

if (count($results->getItems()) == 0) {
  print "No upcoming events found.
<br>";
} else {
  print "Upcoming events:
<br>";
  foreach ($results->getItems() as $event) {
    $start = $event->start->dateTime;
    if (empty($start)) {
      $start = $event->start->date;
    }
    printf("%s (%s)
 <br>", $event->getSummary(), $start);
  }
}

Try and do a calendar.get on USER_CHOSEN@email.com. This will ensure that you have access to the calendar it self. Then double check what permissions you gave the service account. At the very least you are going to need see all event details.

enter image description here

your code looks fine to me I just don't think you have access.