Witam mam problem z ogarnięciem dodawanie eventów do kalendarza google za pomocą ich API. Mam taki kod z dokumentacji
  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3.  
  4.  
  5. define('APPLICATION_NAME', 'Google Calendar API PHP Quickstart');
  6. define('CREDENTIALS_PATH', '~/.credentials/calendar-php-quickstart.json');
  7. define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
  8. // If modifying these scopes, delete your previously saved credentials
  9. // at ~/.credentials/calendar-php-quickstart.json
  10. define('SCOPES', implode(' ', array(
  11. Google_Service_Calendar::CALENDAR)
  12. ));
  13.  
  14. if (php_sapi_name() != 'cli') {
  15. throw new Exception('This application must be run on the command line.');
  16. }
  17.  
  18. /**
  19.  * Returns an authorized API client.
  20.  * @return Google_Client the authorized client object
  21.  */
  22.  
  23.  
  24. function getClient() {
  25. $client = new Google_Client();
  26. $client->setApplicationName(APPLICATION_NAME);
  27. $client->setScopes(SCOPES);
  28. $client->setAuthConfig(CLIENT_SECRET_PATH);
  29. $client->setAccessType('offline');
  30.  
  31. // Load previously authorized credentials from a file.
  32. $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
  33. if (file_exists($credentialsPath)) {
  34. $accessToken = json_decode(file_get_contents($credentialsPath), true);
  35. } else {
  36. // Request authorization from the user.
  37. $authUrl = $client->createAuthUrl();
  38. printf("Open the following link in your browser:\n%s\n", $authUrl);
  39. print 'Enter verification code: ';
  40. $authCode = trim(fgets(STDIN));
  41.  
  42. // Exchange authorization code for an access token.
  43. $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
  44.  
  45. // Store the credentials to disk.
  46. if(!file_exists(dirname($credentialsPath))) {
  47. mkdir(dirname($credentialsPath), 0700, true);
  48. }
  49. file_put_contents($credentialsPath, json_encode($accessToken));
  50. printf("Credentials saved to %s\n", $credentialsPath);
  51. }
  52. $client->setAccessToken($accessToken);
  53.  
  54. // Refresh the token if it's expired.
  55. if ($client->isAccessTokenExpired()) {
  56. $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
  57. file_put_contents($credentialsPath, json_encode($client->getAccessToken()));
  58. }
  59. return $client;
  60. }
  61.  
  62. /**
  63.  * Expands the home directory alias '~' to the full path.
  64.  * @param string $path the path to expand.
  65.  * @return string the expanded path.
  66.  */
  67. function expandHomeDirectory($path) {
  68. $homeDirectory = getenv('HOME');
  69. if (empty($homeDirectory)) {
  70. $homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH');
  71. }
  72. return str_replace('~', realpath($homeDirectory), $path);
  73. }
  74.  
  75. // Get the API client and construct the service object.
  76. $client = getClient();
  77. $service = new Google_Service_Calendar($client);
  78.  
  79. // Print the next 10 events on the user's calendar.
  80. $calendarId = '#######';
  81. $optParams = array(
  82. 'maxResults' => 10,
  83. 'orderBy' => 'startTime',
  84. 'singleEvents' => TRUE,
  85. 'timeMin' => date('c'),
  86. );
  87. $results = $service->events->listEvents($calendarId, $optParams);
  88.  
  89. if (count($results->getItems()) == 0) {
  90. print "No upcoming events found.\n";
  91. } else {
  92. print "Upcoming events:\n";
  93. foreach ($results->getItems() as $event) {
  94. $start = $event->start->dateTime;
  95. if (empty($start)) {
  96. $start = $event->start->date;
  97. }
  98. printf("%s (%s)\n", $event->getSummary(), $start);
  99. }
  100. }
  101. $createdEvent = $service->events->quickAdd(
  102. 'primary',
  103. 'Appointment at Somewhere on June 3rd 10am-10:25am');
  104.  
  105. echo $createdEvent->getId();
  106. ?>

I wszystko działa,wyświetla eventy z kalendarza. Ale do momentu próby dodania eventu. Wtedy wywala mi taki błąd:
  1. PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message '{
  2. "error": {
  3. "errors": [
  4. {
  5. "domain": "global",
  6. "reason": "insufficientPermissions",
  7. "message": "Insufficient Permission"
  8. }
  9. ],
  10. "code": 403,
  11. "message": "Insufficient Permission"
  12. }
  13. }


Miał ktoś już do czynienia z Google API?