So I'm trying to set up an API connection to Google Calendar to be able to create and update events and so on. First, I'm just trying to get the API connection to work.
So I have installed the Google API PHP Client library to my project folder on my website. Then created a Service Account at the IAM & Admin section at the Google Cloud console.
I have created a key for the Service Account and downloaded and uploaded the JSON-file to the project folder on my web server. The JSON file is in the same folder as the Google API connection code where I'm trying to make this working. My code looks like this:
$client = new Google\Client();
$credentials_file = "myproject-123456789.json";
$auth_data = json_decode(file_get_contents($credentials_file), TRUE);
$client->setAuthConfig($auth_data);
$client->setApplicationName("myproject");
$client->setScopes(['https://www.googleapis.com/auth/calendar']);
$service = new Google\Service\Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
But the page crashes. It has something to do with the listCalendarList()
function above because removing that makes it not crashing. So what could it be?
I don't get any error messages anywhere and not even when removing that last line returns in any error message so I assume the authentication is working (?). But why can't I call listCalendarList()
?