Reputation:
I am using google calendar API with PHP as per quickstart documentation but it shows me below errors.
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file does not exist' in C:\xampp\htdocs\google_calender\vendor\google\apiclient\src\Google\Client.php:839
Stack trace:
#0 C:\xampp\htdocs\google_calender\quickstart.php(17): Google_Client->setAuthConfig('C:\\xampp\\htdocs...')
#1 C:\xampp\htdocs\google_calender\quickstart.php(63): getClient()
#2 {main}
thrown in C:\xampp\htdocs\google_calender\vendor\google\apiclient\src\Google\Client.php on line 839
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file do
es not exist' in C:\xampp\htdocs\google_calender\vendor\google\apiclient\src\Google\Client.php:839
Stack trace:
#0 C:\xampp\htdocs\google_calender\quickstart.php(17): Google_Clien
t->setAuthConfig('C:\\xampp\\htdocs...')
#1 C:\xampp\htdocs\google_calender\quickstart.php(63): getClient()
#2 {main}
thrown in C:\xampp\htdocs\google_calender\vendor\google\apiclient\src\Google\Client.php on line 839
I am stuck with this and still didn't get anything.
can anybody help me with this.
Upvotes: 2
Views: 1494
Reputation: 360
The answers here while they are correct, in that you need the credentials.json file, they are incorrect, in that the instructions are clear on the PHP Quickstart page. The instructions are not clear anymore. See the screenshot below for step 1:
How to get the credentials.json file:
Currently, in the prerequisites there is:
A Google Cloud Platform project with the API enabled. To create a project and enable an API, refer to Create a project and enable the API
That brings you to further pages that eventually get you to create the OAuth 2.0 Client IDs. Google Cloud Console > APIs & Services > Credentials > OAuth 2.0 Client IDs. You have to have created an ID. If you have there will be a download option to the right.
Click it and then there is a download json option.
Put the downloaded file into the same folder as the quickstart.php
file and rename it credentials.json.
As far as I could tell there was no clear direction for the credentials.json file being needed. I left feedback on that page regarding this lack of information. If you run into the same problem I suggest you do too.
Upvotes: 0
Reputation: 148
Note very clear instructions in https://developers.google.com/calendar/api/quickstart/php#step_1_turn_on_the.
Even if you use composer you have to follow these steps: https://github.com/googleapis/google-api-php-client#authentication-with-oauth
Upvotes: 0
Reputation: 2342
The file used in the method $client->setAuthConfig('credentials.json');
is not created by running the code. It's created following the Step 1 on the PHP Quickstart. You will get a .json file that will look like this one:
{
"installed":
{
"client_id":"your-id",
"project_id":"your-project- id",
"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_secret":"your-scret",
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob","http://localhost"]
}
}
After you get it, save it in the same place where you have your quickstart.php file.
Upvotes: 2