简体   繁体   中英

How to deploy a PHP Laravel app on Heroku with Google's credentials.json file?

I have a PHP Laravel API, connected with a Google Sheet to retrieve some data. For authentication as a Google Client, I received a credentials.json file that I put in a storage/app/credentials directory on my local machine, which I added to .gitignore to keep it out of version control. I Installed Google Auth Library for PHP and set the path to the credentials.json file as a variable called GOOGLE_APPLICATION_CREDENTIALS in the project's .env file. So $credential below simply holds the path to the JSON file.

$credential = getenv('GOOGLE_APPLICATION_CREDENTIALS');

$client = new Google_Client();
$client->setApplicationName('Pricing Calculator');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$client->setAuthConfig($credential);
$client->setAccessType('offline');

With this, the API works in my local environment, but on production I keep getting back internal server error 500's. I added a buildpack https://github.com/elishaterada/heroku-google-application-credentials-buildpack.git to set credentials.json as a GOOGLE_CREDENTIALS Config Var and assigned google-credentials.json to GOOGLE_APPLICATION_CREDENTIALS , but it seems the credentials.json file is still not configured correctly on the Heroku production server.

I have the feeling it should be working already, but it isn't. So I either lack essential knowledge or I missed some obvious mistake. Both is possible, but anyway... any help or insight would be much appreciated!

The Git repo is here: https://github.com/Spesm/pricing-calculator-api

For documentation purposes, this is related to this comment .

It seems that the buildpack used on the linked question is not working. The suggested alternative is to use this buildpack instead .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM