且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase Cloud Function的403状态-> Google Books API

更新时间:2023-01-18 12:40:51

我遇到了类似的问题.在本地运行函数(即firebase serve)时,我能够成功使用Books API.但是,当我将功能和应用程序部署到托管时,我得到了一个神秘的403: Forbidden错误.

I was facing a similar issue. I was able to sucessfully use the Books API when I was running my functions locally (ie. firebase serve). But when I deployed the functions and the app to hosting, I was getting a mysterious 403: Forbidden error.

我尝试了几件事,所以不确定是否有帮助,所以我只列出所有内容:

I tried several things so I'm not sure which helped so I'll just list everything:

  • 更新的firebase功能:npm install --save firebase-functions@latest
  • 从使用node-fetch切换为使用axios来调用API
  • 将国家/地区添加到URL:https://www.googleapis.com/books/v1/volumes?country=US&q=insubject:${randomWord}&key=${functions.config().books.api.key}
  • 重新生成的Google Books API密钥
  • 删除了Google云控制台中的所有Application restrictions
  • Updated firebase functions: npm install --save firebase-functions@latest
  • Switched from using node-fetch to using axios for calling the API
  • Add country to URL: https://www.googleapis.com/books/v1/volumes?country=US&q=insubject:${randomWord}&key=${functions.config().books.api.key}
  • Regenerated Google Books API key
  • Removed all Application restrictions in the google cloud console

希望这对外面的人有帮助,因为我已经花了好几个小时了!

Hope this helps somebody out there because I was wrestling with it for hours!