Код: Выделить всё
"Permission 'cloudmessaging.messages.create' denied on resource
'//cloudresourcemanager.googleapis.com/projects/xxxxx' (or it may not exist)
Код: Выделить всё
function getAccessToken($serviceAccountPath) {
static $cachedToken = null;
static $tokenExpiry = null;
if ($cachedToken && $tokenExpiry > time()) {
return $cachedToken;
}
$client = new Google_Client();
$client->setAuthConfig($serviceAccountPath);
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
$client->useApplicationDefaultCredentials();
$token = $client->fetchAccessTokenWithAssertion();
$cachedToken = $token['access_token'];
$tokenExpiry = time() + $token['expires_in'] - 60; // Store token expiry time
return $cachedToken;
}

Подробнее здесь: https://stackoverflow.com/questions/797 ... dresourcem