Uncaught exception 'InvalidArgumentException&#

2019-02-25 13:44发布

I have copied the code in their documentation on this site: here.

I have changed the JSON on these below. I have generated a fresh files on API on the composer, but I am still having some issues. I'm not sure what have I done wrong. Does this mean their API is way too buggy?

Here is the demo link: demo

define('APPLICATION_NAME', 'Ashima');
define('CREDENTIALS_PATH', '/mycredentials.json');
define('CLIENT_SECRET_PATH', __DIR__ .'/mysecret.apps.googleusercontent.com.json');

Error:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file does not exist' in /var/www/mysite/googleapi2/vendor/google/apiclient/src/Google/Client.php:839 Stack trace: #0 /var/www/mysite/googleapi2/quick.php(32): Google_Client->setAuthConfig('/var/www/payrol...') #1 /var/www/mysite/googleapi2/quick.php(80): getClient() #2 {main} thrown in /var/www/mysite/googleapi2/vendor/google/apiclient/src/Google/Client.php on line 839

2条回答
ら.Afraid
2楼-- · 2019-02-25 14:26

Here I'm:

1) "CREDENTIALS_PATH" should point to a nonexistent file (in a writable path)

2) "CLIENT_SECRET_PATH" should point to the "ID client OAuth 2.0" credential file, created and downloaded from the Google Console in the Api Credential section.

For a server side php script, like yours, pay attention when creating the "ID client OAuth 2.0" record: on the creation wizard, you should select "other" type of application and not the "web" type.

Regards

查看更多
戒情不戒烟
3楼-- · 2019-02-25 14:43

The CLIENT_SECRET_PATH is not the CLIENT ID JSON file.

After creating the OAuth 2.0 client IDs for the project from below link you need to create a service account keys, to do this follow those steps:

  1. From here https://console.developers.google.com/apis/credentials
  2. Click Create Credentials
  3. Choose service account keys
  4. Select the service account and keep JSON checked.
查看更多
登录 后发表回答