I'm trying to get an access token to make REST calls to my Firestore DB. I'm using PHP (only way for now) and have taken the next steps:
- Created a service account in the Firebase console and downloaded the key JSON
- Downloaded the Google-api-php library from https://developers.google.com/api-client-library/php/ and included in my code
And created this code:
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__ .'/key.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/datastore,https://www.googleapis.com/auth/cloud-platform');
$client->authorize();
I also replaced the
$client->useApplicationDefaultCredentials();
part with
$client->setAuthConfig(__DIR__ .'/key.json');
Now when I var_dump the $client, the token stays NULL.
I just can't figure out, how to get the access_token for my service account. Anybody an idea how I can get an access token?