<?php require_once __DIR__ . '/vendor/autoload.php'; // If modifying these scopes, delete your previously saved credentials // at ~/.credentials/calendar-php-quickstart.json Google_Service_Calendar::CALENDAR) )); if (php_sapi_name() != 'cli') { throw new Exception('This application must be run on the command line.'); } /** * Returns an authorized API client. * @return Google_Client the authorized client object */ function getClient() { $client = new Google_Client(); $client->setApplicationName(APPLICATION_NAME); $client->setScopes(SCOPES); $client->setAuthConfig(CLIENT_SECRET_PATH); $client->setAccessType('offline'); // Load previously authorized credentials from a file. $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); } else { // Request authorization from the user. $authUrl = $client->createAuthUrl(); // Exchange authorization code for an access token. $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); // Store the credentials to disk. } file_put_contents($credentialsPath, json_encode($accessToken)); } $client->setAccessToken($accessToken); // Refresh the token if it's expired. if ($client->isAccessTokenExpired()) { $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); file_put_contents($credentialsPath, json_encode($client->getAccessToken())); } return $client; } /** * Expands the home directory alias '~' to the full path. * @param string $path the path to expand. * @return string the expanded path. */ function expandHomeDirectory($path) { } } // Get the API client and construct the service object. $client = getClient(); $service = new Google_Service_Calendar($client); // Print the next 10 events on the user's calendar. $calendarId = '#######'; 'maxResults' => 10, 'orderBy' => 'startTime', 'singleEvents' => TRUE, ); $results = $service->events->listEvents($calendarId, $optParams); } else { foreach ($results->getItems() as $event) { $start = $event->start->dateTime; $start = $event->start->date; } } } $createdEvent = $service->events->quickAdd( 'primary', 'Appointment at Somewhere on June 3rd 10am-10:25am'); ?>
I wszystko działa,wyświetla eventy z kalendarza. Ale do momentu próby dodania eventu. Wtedy wywala mi taki błąd:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ], "code": 403, "message": "Insufficient Permission" } }
Miał ktoś już do czynienia z Google API?