Google Cloud API - Application Default Credentials
<p>I have the following code, modified from <a href="https://developers.google.com/identity/protocols/application-default-credentials" rel="noreferrer">Google's documentation</a>:</p>

<pre><code>        $GOOGLE_APPLICATION_CREDENTIALS = "./[path].json";
        $_ENV["GOOGLE_APPLICATION_CREDENTIALS"] = "./[path].json";
        $_SERVER["GOOGLE_APPLICATION_CREDENTIALS"] = "./[path].json";

        $projectId = "[my project's ID']";
        $client = new Google_Client();
        $client-&gt;useApplicationDefaultCredentials();
        $client-&gt;setScopes(['https://www.googleapis.com/auth/books']);
        $service = new Google_Service_Books($client);
        $results = $service-&gt;volumes-&gt;listVolumes('Henry David Thoreau');
</code></pre>

<p>Yet when I run it it returns the error:</p>

<pre><code>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'
</code></pre>

<p>I have tried various configurations, for example changing the path of the file. As you see, I've also done the three different forms of variables that I could immediately think of (two environment, one not).</p>

<p>I'm not quite sure where to look next. Should I look into different ways of setting the environment variable or should I define the path in a different way? What are the correct ways of doing this? Is there any other reason for the error?</p>