Uncaught exception 'InvalidArgumentException' with message ' on Google API

断了今生、忘了曾经 提交于 2019-12-02 04:06:33

问题


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


回答1:


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.



回答2:


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



来源:https://stackoverflow.com/questions/39524864/uncaught-exception-invalidargumentexception-with-message-on-google-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!