Firebase云消息推送:如何获取公共VAPID密钥?

48

我正在通过Firebase为Web应用程序实现推送通知,并遵循Google的指南。

https://github.com/firebase/quickstart-js/tree/master/messaging

我在index.html中看到了这段代码

    // [START get_messaging_object]
    // Retrieve Firebase Messaging object.
    const messaging = firebase.messaging();
    // [END get_messaging_object]

    // [START set_public_vapid_key]
    // Add the public key generated from the console here.
    messaging.usePublicVapidKey('<YOUR_PUBLIC_VAPID_KEY_HERE>');
    // [END set_public_vapid_key]

我的问题是:“什么是Vapid Key?我在哪里可以找到这个密钥?”

1个回答

130
基于https://firebase.google.com/docs/cloud-messaging/js/client

Vapid Key是“自愿应用服务器识别码”,我们可以在以下位置找到它:

  1. 打开Firebase控制台的设置面板中的Cloud Messaging标签,并滚动到Web配置部分。
  2. Web Push证书选项卡中,单击生成密钥对。控制台显示已生成密钥对的通知,并显示公共密钥字符串和添加日期。

或查看下面的步骤图像

  1. 打开项目设置

enter image description here

在{{Cloud Messaging}}中选择,向下滚动至{{Web configuration}}。在{{Web Push certificates}}中,您可以找到Vapid密钥(如果不存在,请单击{{Generate Key Pair}}创建)。

enter image description here

enter image description here


谢谢,我用它来做 flutter_messaging,好的。 - Amir Farahani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接