Home > Mobile >  Cannot enable the Google Calendar Cloud API
Cannot enable the Google Calendar Cloud API

Time:05-24

I spoke with Google Workspace customer support and they failed to find appropriate documentation about this issue. They directed me here.

Very simply, I'm trying to enable the Google Cloud API to create an event in a user's calendar (and hopefully adding a Google Meet URL to it) as per this document: https://developers.google.com/calendar/api/guides/create-events.

I am following the Quickstart PHP code sample which first instructs to install the SDK via composer and authorize the Google Cloud API in PHP. That link is here: https://developers.google.com/calendar/api/quickstart/php.

The script (Step 2) provided by that page initially failed (during Step 3) with the following error:

PHP Fatal error:  Uncaught InvalidArgumentException: file "credentials.json" does not exist in /path/to/vendor/Google/google/apiclient/src/Client.php:984

Stack trace: #0 /path/to/app_root/quickstart.php(17): Google\Client->setAuthConfig('credentials.jso...') #1 /path/to/app_root/quickstart.php(63): getClient() #2 {main} thrown in /path/to/vendor/Google/google/apiclient/src/Client.php on line 984

I have created a service account as per the instruction here:

Although the instructions did not include steps to create a service account and generate JSON keys, I found that solution online, and it was verified by the Google Workspace support agent. I downloaded and renamed that file and put it in the script root directory (although the path was not specified in the incomplete documentation either, this was verified by the Google Workspace support agent). I ran the script again and received this error:

PHP Fatal error:  Uncaught InvalidArgumentException: missing the required redirect URI in /path/to/vendor/Google/google/auth/src/OAuth2.php:694
Stack trace:
#0 /path/to/vendor/Google/google/apiclient/src/Client.php(406): Google\Auth\OAuth2->buildFullAuthorizationUri(Array)
#1 /path/to/app_root/quickstart.php(38): Google\Client->createAuthUrl()
#2 /path/to/app_root/quickstart.php(63): getClient()
#3 {main}
  thrown in /path/to/vendor/Google/google/auth/src/OAuth2.php on line 694

I have tried to create an OAuth redirect URI and regenerated the JSON keys, however, the same error occurred. Here is the authentication JSON file that I downloaded from the service account KEYS section with any account specific information redacted:

{
  "type": "service_account",
  "project_id": "massive-clone-{REDACTED}",
  "private_key_id": "{REDACTED}",
  "private_key": "-----BEGIN PRIVATE KEY-----{REDACTED}\n-----END PRIVATE KEY-----\n",
  "client_email": "calendar-api@massive-clone-{REDACTED}.iam.gserviceaccount.com",
  "client_id": "{REDACTED}",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/calendar-api@massive-clone-{REDACTED}.iam.gserviceaccount.com"
}

Although the quickstart guide seems to address this issue in the troubleshooting section, the advise does not seem to apply since there is no "button" in Step 1. From the troubleshooting section:

Uncaught InvalidArgumentException: missing the required redirect URI

This error occurs when the credentials.json file used contains a client ID of the wrong type. This code requires an OAuth client ID of type Other, which will be created for you when using the button in Step 1. If creating your own client ID please ensure you select the correct type.

Can anyone help me understand how to get the appropriate credentials.json file? I'm not sure about how this process is supposed to go, but the Google Workspace support agent said they could not find any documentation and directed me here. If my question needs to be specified in an different way, please advise.

CodePudding user response:

Your code is trying to use a service account. The example uses use OAuth Client Secrets.

Setting up OAuth 2.0

  • Related