0
votes

Can I ask you if there is anybody who can answer me a question about Google Calendar API? I have generated credentials and on localhost it works pretty fine. I just want to return like 100 upcoming events ($service->events->listEvents($calendarId, $optParams) but this same code on production doesn`t works, it returns 500 Internal Server Error especially on this piece of code. Any advice how to continue?

this is the piece of code and it breaks on the first commented line

<?php

require './vendor/autoload.php';

$client = new Google_Client();
$gazza = new GuzzleHttp\Client([
    'verify' => './cacert.pem'
]);
$client->setApplicationName('Google Calendar API PHP Quickstart');
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAuthConfig('./credentials-calendar-old.json');
$client->setAccessType('offline');

$tokenPath = 'token.json';
if (file_exists($tokenPath)) {
    $accessToken = json_decode(file_get_contents($tokenPath), true);
    $client->setAccessToken($accessToken);
}

$service = new Google_Service_Calendar($client);

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

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

// Print the next 10 events on the user's calendar.
$calendarId = 'primary';
$optParams = array(
    'maxResults' => 1000,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    'timeMin' => date('c'),
);

Thanks a lot,

Alex

1
this post needs more information, the 500 server error means that the function ended with a crash. the crash could have happened from a type error to errors on calling external services, you need to find where your code is broken.Raphael Castro
I post a piece of code and the URL which gives me 500 is www.pedagogickydiar.com/kalendarAlexander Vachuška
you have errors in your code: [Error] Viewport argument key "minimal-ui" not recognized and ignored. (kalendar, line 1) [Error] TypeError: null is not an object (evaluating 'document.getElementById('ypembedcontainer').style') yp_emb_resp_check (yp_r_iframe.js:9) Global Code (yp_r_iframe.js:13) [Error] Unhandled Promise Rejection: SyntaxError: The string did not match the expected pattern. (anonymous function) promiseReactionJob [Error] TypeError: null is not an object (evaluating 'document.getElementById('ypembedcontainer').style') yp_emb_resp_check (yp_r_iframe.js:9)Raphael Castro

1 Answers

0
votes

Try to remove the code below, as far as I know this code is just for localhost, to force https.

$gazza = new GuzzleHttp\Client([
    'verify' => './cacert.pem'
]);