Skip to content
Advertisement

Using Environment Variables as Credentials on Heroku

I need to make the “google-credentials.json” file works on heroku it’s working locally by putting the local path on my laptop but in heroku I don’t know how to do it.

I search a lot, I found this solutions How to use Google API credentials json on Heroku? but I couldn’t make it works maybe the solution is old or I did it wrong the solution is to:

1 – Declare your env variables from in Heroku dashboard 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 :

JavaScript

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

This is my vars and Buildpacks: This is my vars and Buildpacks

This is the Error Logs:

JavaScript

This is the python code:

JavaScript

And I would someone can help me thanks a Lot

Advertisement

Answer

Thanks God I finally Solved this issue Instead of Using Environment Variables which have the credentials file name and the json credential script and then using Buildpack to Generate local path You Just need to Create New Json File then write the credentials script inside and finally pass the new Json File name as a parameter to the LoadCredentialsFile Function Like This:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement