I installed the Google SDK to use the Google API with the default Credentials for the application . For my local machine, create a json credential file and specify its path GOOGLE_APPLICATION_CREDENTIALSas an environment variable. This works without a problem.
However, when the application is deployed to the Google Virtual Machine, it causes the following error:
[Google_Service_Exception]
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"errors": [
{
"message": "Request had insufficient authentication scopes.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
According to the documentation , the built-in service account must be associated with a virtual machine instance. To make it work, I tried to use the credentials of the json file, as on the local computer (which worked fine), but it did not work either.
, , auth. , Compute Engine VM?
:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Pubsub::PUBSUB);