How to use Google API credentials json on Heroku?

I spent an entire day to find the solution because it’s tricky.
No matter your language, the solution will be the same.

1 – Declare your env variables from in Heroku dashboard like :

The GOOGLE_CREDENTIALS variable is the content of service account credential JSON file as is.
The GOOGLE_APPLICATION_CREDENTIALS env variable in the string “google-credentials.json”

2 – Once variables are declared, add the builpack from command line :

$ heroku buildpacks:add https://github.com/elishaterada/heroku-google-application-credentials-buildpack

3 – Make a push. Update a tiny thing and push.

4 – The buildpack will automatically generate a google-credentials.json and fill it with the content of the google credentials content.

If you failed at something, it will not work. Check the content of the google-credentials.json with the Heroku bash.

Leave a Comment