带有“请求包含无效身份验证凭据”的Google Analytics Reporting API V4

We use this walk through, to set up our tool. Hello Analytics Reporting API V4; PHP quickstart for service accounts

Here is the example from the walkthrough https://advertisebg.com/report1610/GA/HelloAnalytics.php and the code is Exactly the same as in the example

Fatal error: Uncaught Google_Service_Exception: { "error": { "code": 401, "message": "Request had invalid authentication credentials.", "errors": [ { "message": "Request had invalid authentication credentials.", "domain": "global", "reason": "unauthorized" } ], "status": "UNAUTHENTICATED" } } in /home/advbg/public_html/report1610/GA/src/Google/Http/REST.php:118 Stack trace: #0 /home/advbg/public_html/report1610/GA/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /home/advbg/public_html/report1610/GA/src/Google/Task/Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /home/advbg/public_html/report1610/GA/src/Google/Http/REST.php(58): Google_Task_Runner->run() #3 /home/advbg/public_html/report1610/GA/src/Google/Client.php(782): Google_Http_REST::execute(Object(GuzzleHttp\Client), in /home/advbg/public_html/report1610/GA/src/Google/Http/REST.php on line 118

After several hours without any problems we receives the following error “Request had invalid authentication credentials”

Several times we restart with new project, recreate the Credentials, install new example and every time - the same result, after having working well for couple of hours, we see the error above.

Any ideas?

It looks like this might be a problem with the Google PHP client library there is current a issue going on the forum for it.

Sporadic "Invalid Credentials" Issues - Service Account

The client library should be refreshing authentication for you seams it isn't. Might be worth following the issue.