简体   繁体   中英

How to authenticate google-vision api credentials on heroku using node.js?

I am running a Node.js application on localhost, which uses Google Vision API to process an image. I am able to authenticate the API locally by providing the path to the .json file, however when I deploy my application to Heroku, it fails to process the API call and I am assuming the reason behind this would be that it is failing API authentication. How can I authenticate the Google-Vision API on Heroku using the .json file provided by google cloud?

If anyone is still looking for this answer, without installing any additional npm package, I solve the authentication issue by checking https://devcenter.heroku.com/articles/config-vars and setting it in my app this way:

  1. place the .json file in the root directory of the app, then deploy it to heroku

  2. Go to settings in your heroku app and set a new CONFIG VARIABLE like this:

    key : GOOGLE_APPLICATION_CREDENTIALS

    value: MYCREDENTIALS.json

**** note the name of the file has no quotes (""), click add and it should work.

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