【问题标题】:Reference path for service account key服务帐号密钥的参考路径
【发布时间】:2017-12-04 11:07:12
【问题描述】:

我指的是下一篇文章what is "serviceAccountKey.json" referring to in the Firebase device-to-device notifications tutorial

index.js 文件中写了一条语句

var serviceAccount = require("path/to/serviceAccountKey.json");

我想知道在谷歌云功能网页界面中编写脚本时这里的路径是什么。

我是否必须将json文件上传到bucket上,然后给出bucket参考路径?

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    您应该将您的 serviceAccountKey.json 与您的 index.json 放在同一文件夹中。然后,当您部署到 Cloud Functions 时,代码和密钥文件都将被上传,您可以通过以下方式引用代码中的 JSON:

    var serviceAccount = require("./serviceAccountKey.json");
    

    请注意,这些天您可能需要考虑使用Admin SDK for Firebase Cloud Messaging 发送消息。这个 SDK 在我写博文的时候并不存在,但是让发送消息的代码更简单(以使用额外的 SDK 为代价)。

    【讨论】:

    • 非常感谢弗兰克,这个建议帮助我上传了脚本。正如您正确提到的有关使用 Admin SDK 的内容,我对博客脚本做了一些更改,但我不得不注释掉调用函数本身以继续侦听“listenForNotificationRequests();”的最后一条语句。删除后,有什么方法可以在脚本上传后保持函数运行。 - 谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-03-04
    • 2022-08-17
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多