Witam mam problem z ogarnięciem dodawanie eventów do kalendarza google za pomocą ich API. Mam taki kod z dokumentacji
<?php
require_once __DIR__ . '/vendor/autoload.php';
define('APPLICATION_NAME', 'Google Calendar API PHP Quickstart'); define('CREDENTIALS_PATH', '~/.credentials/calendar-php-quickstart.json'); define('CLIENT_SECRET_PATH', __DIR__
. '/client_secret.json'); // 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();
printf("Open the following link in your browser:\n%s\n", $authUrl); print 'Enter verification code: ';
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath); }
$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) {
$homeDirectory = getenv('HOME'); if (empty($homeDirectory)) { }
}
// 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);
if (count($results->getItems()) == 0
) { print "No upcoming events found.\n"; } else {
print "Upcoming events:\n"; foreach ($results->getItems() as $event) {
$start = $event->start->dateTime;
$start = $event->start->date;
}
printf("%s (%s)\n", $event->getSummary(), $start); }
}
$createdEvent = $service->events->quickAdd(
'primary',
'Appointment at Somewhere on June 3rd 10am-10:25am');
echo $createdEvent->getId(); ?>
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?