谷歌日历 API 与 PHP 的问题

根据快速入门文档,我正在使用带有 PHP 的谷歌日历 API,但它显示了以下错误。


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

我坚持这一点,仍然没有得到任何东西。


任何人都可以帮我解决这个问题。


阿晨1998
浏览 169回答 2
2回答

米琪卡哇伊

该方法$client->setAuthConfig('credentials.json');中使用的文件不是通过运行代码创建的。它是按照PHP Quickstart上的第 1 步创建的。您将获得一个.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 文件的同一位置。

拉风的咖菲猫

这里的答案是正确的,因为您需要 credentials.json 文件,但它们是不正确的,因为 PHP 快速入门页面上的说明很清楚。指示不再清晰。请参阅下面的屏幕截图以了解第 1 步:如何获取 credentials.json 文件:目前,在先决条件中有:启用了 API 的 Google Cloud Platform 项目。要创建项目并启用 API,请参阅创建项目并启用 API这会将您带到更多页面,最终让您创建 OAuth 2.0 客户端 ID。Google Cloud Console > API 和服务 > 凭据 > OAuth 2.0 客户端 ID。您必须已经创建了一个 ID。如果你有,右边会有一个下载选项。单击它,然后有一个下载 json 选项。将下载的文件放入与文件相同的文件夹中quickstart.php,并将其重命名为 credentials.json。据我所知,需要的 credentials.json 文件没有明确的方向。我在该页面上留下了关于缺乏信息的反馈。如果你遇到同样的问题,我建议你也这样做。
打开App,查看更多内容
随时随地看视频慕课网APP