I\'m making an app using Google Calendar API, and planning to build it on Heroku.
I have a problem about authentication. Usually I use credential json file for that, but
As state above, the official Heroku documentation works (https://elements.heroku.com/buildpacks/buyersight/heroku-google-application-credentials-buildpack).
For PHP Laravel users though, the config variable GOOGLE_APPLICATION_CREDENTIALS
should be set to ../google-credentials.json
. Otherwise, PHP will not find the file.
Screenshot from Heroku
You can create the JSON key file by adding a .profile
file to the repo, which will be executed when Heroku starts up the container.
Set a config variables:
heroku config:set GOOGLE_APPLICATION_CREDENTIALS=gcp_key.json
heroku config:set GOOGLE_CREDENTIALS=<CONTENTS OF YOU GCP KEY>
The GOOGLE_CREDENTIALS is easier to set in the Heroku dashboard.
Create a .profile
with a line to write the json file:
echo ${GOOGLE_CREDENTIALS} > /app/gcp_key.json
Obviously, commit the changes to .profile
and push to heroku.
The recommended buildpack doesn't work anymore and, in any case, this feels more direct without being hard.
you can change the scripts like this in your packge.json, set the file json path in GOOGLE_APPLICATION_CREDENTIALS
"scripts": {
"start": "GOOGLE_APPLICATION_CREDENTIALS=./yourfile.json node app.js"
}
The buildpack mentioned by Maxime Boué is not working anymore because of the Heroku updates(18+). However, below is a similar buildpack which is working. It is actually a fork from the previous one.