I have the following code modified from google documentation :
$GOOGLE_APPLICATION_CREDENTIALS = "./[path].json"; $_ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "./[path].json"; $_SERVER["GOOGLE_APPLICATION_CREDENTIALS"] = "./[path].json"; $projectId = "[my project ID']"; $client = new Google_Client(); $client->useApplicationDefaultCredentials(); $client->setScopes(['https://www.googleapis.com/auth/books']); $service = new Google_Service_Books($client); $results = $service->volumes->listVolumes('Henry David Thoreau');
But when I run it, it returns an error:
PHP Fatal error: Uncaught exception 'DomainException' with message 'Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information'
I tried various configurations, for example, changing the path to the file. As you can see, I also made three different forms of variables that I could immediately think of (two environments, not one).
I'm not quite sure where to look next. Should I look for different ways to set the environment variable or should I define the path differently? What are the right ways to do this? Is there another reason for the error?
source share