google 日历 API 与 PHP 的问题
issue with google calender API with PHP
我根据快速入门文档使用 google 日历 API 和 PHP,但它显示以下错误。
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
我被这个问题困住了,但仍然没有得到任何东西。
谁能帮我解决这个问题。
方法 $client->setAuthConfig('credentials.json');
中使用的文件不是由 运行 代码创建的。它是在 Step 1 on the PHP Quickstart 之后创建的。你会得到一个 .json 文件,看起来像这样:
{
"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"]
}
}
获取后,将其保存在 quickstart.php 文件所在的位置.
请注意 https://developers.google.com/calendar/api/quickstart/php#step_1_turn_on_the 中非常明确的说明。
即使您使用 Composer,您也必须遵循以下步骤:https://github.com/googleapis/google-api-php-client#authentication-with-oauth
这里的答案是正确的,因为您需要 credentials.json 文件,但它们是不正确的,因为 PHP 快速入门页面上的说明很清楚。说明已经不清楚了。请参阅下面的第 1 步屏幕截图:
如何获取 credentials.json 文件:
目前,先决条件中有:
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
这会将您带到更多页面,最终让您创建 OAuth 2.0 客户端 ID。 Google Cloud Console > API 和服务 > 凭据 > OAuth 2.0 客户端 ID。您必须已经创建了一个 ID。如果有,右边会有下载选项。
点击后有下载json选项
将下载的文件放入与quickstart.php
文件相同的文件夹中并重命名为credentials.json.
据我所知,需要 credentials.json 文件没有明确的方向。我在该页面上留下了关于缺乏信息的反馈。如果你 运行 遇到同样的问题,我建议你也这样做。
我根据快速入门文档使用 google 日历 API 和 PHP,但它显示以下错误。
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
我被这个问题困住了,但仍然没有得到任何东西。
谁能帮我解决这个问题。
方法 $client->setAuthConfig('credentials.json');
中使用的文件不是由 运行 代码创建的。它是在 Step 1 on the PHP Quickstart 之后创建的。你会得到一个 .json 文件,看起来像这样:
{
"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"]
}
}
获取后,将其保存在 quickstart.php 文件所在的位置.
请注意 https://developers.google.com/calendar/api/quickstart/php#step_1_turn_on_the 中非常明确的说明。
即使您使用 Composer,您也必须遵循以下步骤:https://github.com/googleapis/google-api-php-client#authentication-with-oauth
这里的答案是正确的,因为您需要 credentials.json 文件,但它们是不正确的,因为 PHP 快速入门页面上的说明很清楚。说明已经不清楚了。请参阅下面的第 1 步屏幕截图:
如何获取 credentials.json 文件:
目前,先决条件中有:
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
这会将您带到更多页面,最终让您创建 OAuth 2.0 客户端 ID。 Google Cloud Console > API 和服务 > 凭据 > OAuth 2.0 客户端 ID。您必须已经创建了一个 ID。如果有,右边会有下载选项。
点击后有下载json选项
将下载的文件放入与quickstart.php
文件相同的文件夹中并重命名为credentials.json.
据我所知,需要 credentials.json 文件没有明确的方向。我在该页面上留下了关于缺乏信息的反馈。如果你 运行 遇到同样的问题,我建议你也这样做。