I spoke with Google Workspace customer support, but they were unable to find proper documentation on this issue. They guided me here.
It's simple, I'm trying to enable the Google Cloud API to create an event in a user's calendar (and want to add a Google Meet URL to it) as per the following documentation: https://developers.google.com/calendar/api/guides/create -events.
I'm following the quickstart PHP code example, which first instructs you to install the SDK through Composer and authorize the Google Cloud API in PHP. The link is at: https://developers.google.com/calendar/api/quickstart/php.
The script provided on this page (step 2) initially fails (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} Throwing in /path/to/vendor/Google/google/apiclient/src/Client.php line 984
I have created a service account following the instructions here:
Although the steps to create a service account and generate a JSON key are not included in the instructions, I found this solution online and it was verified by a Google Workspace support agent. I downloaded and renamed the file and placed it in the script root directory (this was verified by a Google Workspace support agent, although the path is not specified in the incomplete documentation either). I run the script again and get 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 tried creating the OAuth redirect URI and regenerating the JSON key, but the same error occurred. Here is the authentication JSON file I downloaded from the Service Account KEYS section, with any account specific information edited:
{ "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%40massive-clone-{REDACTED}.iam.gserviceaccount.com" }
Although the quick start guide seems to address this issue in the troubleshooting section, the advice doesn't seem to apply because there is no "button" in step 1. From the troubleshooting section:
Uncaught InvalidArgumentException: Required redirect URI is missing
When using the credentials.json file contains Wrong client ID type. This code requires an OAuth client ID Enter "Other" and it will be created for you when you use the button Step 1. If creating your own client ID, make sure you select Correct type.
Can anyone help me figure out how to get the appropriate credentials.json
file? I'm not sure how this process is supposed to work, but the Google Workspace support agent said they couldn't find any documentation and directed me here. If my question needs to be specified differently, please let me know.
P粉3164230892024-02-27 13:45:20
Your code is trying to use a service account. This example uses an OAuth client secret.