2015-08-23 10 views
4

Я пытаюсь создать событие. В моем календаре Google перечислены события правильно, но когда я пытаюсь вставить событие, это приводит к ошибке. Что я делаю неправильноВставка календаря Google дает 403 ошибку разрешения

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events: (403) Insufficient Permission' in /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Http/REST.php:110 Stack trace: #0 /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array) #3 /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Http/REST.php(46): Google_Task_Runner->run() #4 /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Client.php(590): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #5 /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Service in /Library/WebServer/Documents/vendor/google/apiclient/src/Google/Http/REST.php on line 110 

вот мой код.

<?php 
require 'vendor/autoload.php'; 
date_default_timezone_set('America/Denver'); 

define('APPLICATION_NAME', 'Google Calendar API Quickstart'); 
define('CREDENTIALS_PATH', '/tmp/calendar-api-quickstart.json'); 
define('CLIENT_SECRET_PATH', 'client_secret.json'); 
define('SCOPES', implode(' ', array(
    Google_Service_Calendar::CALENDAR) 
)); 

/** 
* 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->setAuthConfigFile(CLIENT_SECRET_PATH); 
    $client->setAccessType('offline'); 

    // Load previously authorized credentials from a file. 
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH); 
    if (file_exists($credentialsPath)) { 
    $accessToken = file_get_contents($credentialsPath); 
    } 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: '; 
    $authCode = '4/ubgInVASpWF5A3zk0hf0ugqwQt__4GOWEGQ7xzHYlTQ'; 

    // Exchange authorization code for an access token. 
    $accessToken = $client->authenticate($authCode); 
error_log(json_encode($credentialsPath)); 
    // Store the credentials to disk. 
    if(!file_exists(dirname($credentialsPath))) { 
     mkdir(dirname($credentialsPath), 0700, true); 
    } 
    file_put_contents($credentialsPath, $accessToken); 
    printf("Credentials saved to %s\n", $credentialsPath); 
    } 
    $client->setAccessToken($accessToken); 

    // Refresh the token if it's expired. 
    if ($client->isAccessTokenExpired()) { 
    $client->refreshToken($client->getRefreshToken()); 
    file_put_contents($credentialsPath, $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)) { 
    $homeDirectory = getenv("HOMEDRIVE") . getenv("HOMEPATH"); 
    } 
    return str_replace('~', realpath($homeDirectory), $path); 
} 
error_log("here"); 
// Get the API client and construct the service object. 
$client = getClient(); 
$service = new Google_Service_Calendar($client); 

$event = new Google_Service_Calendar_Event(array(
    'summary' => 'Google I/O 2015', 
    'location' => '800 Howard St., San Francisco, CA 94103', 
    'description' => 'A chance to hear more about Google\'s developer products.', 
    'start' => array(
     'dateTime' => '2015-08-28T09:00:00-07:00', 
     'timeZone' => 'America/Los_Angeles', 
    ), 
    'end' => array(
     'dateTime' => '2015-08-28T17:00:00-07:00', 
     'timeZone' => 'America/Los_Angeles', 
    ), 
    'recurrence' => array(
     'RRULE:FREQ=DAILY;COUNT=2' 
    ), 
    'attendees' => array(
     array('email' => '[email protected]'), 
     array('email' => '[email protected]'), 
    ), 
    'reminders' => array(
     'useDefault' => FALSE, 
     'overrides' => array(
      array('method' => 'email', 'minutes' => 24 * 60), 
      array('method' => 'popup', 'minutes' => 10), 
     ), 
    ), 
)); 

$calendarId = 'primary'; 
$event = $service->events->insert($calendarId, $event); 
printf('Event created: %s\n', $event->htmlLink); 





// Print the next 10 events on the user's calendar. 
$calendarId = 'primary'; 
$optParams = array(
    'maxResults' => 10, 
    'orderBy' => 'startTime', 
    'singleEvents' => TRUE, 
    'timeMin' => date('c'), 
); 
$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; 
    if (empty($start)) { 
     $start = $event->start->date; 
    } 
    printf("%s (%s)\n", $event->getSummary(), $start); 
    } 
} 

ответ

8

А я думаю, что я понял это

так, когда вы запрашиваете знак (прицелы)

Google_Service_Calendar :: CALENDAR_READONLY

это создать учетную файл в моем каталоге TMP и все оттуда были маркеры. Я должен был удалить, что и регенерируют лексем с этим

Google_Service_Calendar :: КАЛЕНДАРЬ

И тогда я смог создать события

благодаря

+1

спас меня утром! – Leo

Смежные вопросы