Firebase消息传递,未收到消息

时间:2019-04-11 10:52:50

标签: firebase firebase-cloud-messaging

我的云功能声明它已成功发送消息const functions = require("firebase-functions"); const admin = require("firebase-admin"); var serviceAccount = require("./config.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://pushmessage-bd1eb.firebaseio.com" }); const messaging = admin.messaging(); const message = { data: { title: "Testing", body: "Test" }, token: "fm8hZocb9X0:APA91bGANY8U1k7iXSAofh8PEtyA3SfkAvyvicjHbSzDC7s1DwzhCxBBhj5oeAhiZpNLFC1wUHOPX_C0vlGtUMv882EXxBjsM4qeBpFndka8kzir9kgmJnuPTRImx2cxUT53oXzJuAzB" }; messaging.send(message).then(response => { console.log( response.successCount + " messages were sent successfully" ); }); ,但我没有收到它:

{
  "type": "service_account",
  "project_id": "pushmessage-bd1eb",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\nxxx-----END PRIVATE KEY-----\n",
  "client_email": "firebase-adminsdk-8dd2o@pushmessage-bd1eb.iam.gserviceaccount.com",
  "client_id": "xxx",
  "senderID": "388436954224",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-8dd2o%40pushmessage-bd1eb.iam.gserviceaccount.com"
}

如果我在Firebase仪表板中使用相同的令牌发送消息,则消息发送成功。

如何让我的云功能发送消息?

config.json:

{{1}}

1 个答案:

答案 0 :(得分:0)

您是否正在使用admin.messaging()。send()?

请参阅:

请尝试以下代码。

NP.append(XX) np.shape(NP) print(np.shape(NP)) 更改为data

然后admin.messaging()。send()返回字符串。

notification

或者您可以使用admin.messaging()。sendToDevice()。

请参阅:

请尝试以下代码。

      const message = {
        notification: { title: "Testing", body: "Test" },
        token:
            "The registration token here"
      };

      admin.messaging().send(message).then(response => {
        console.log(
            response + " messages were sent successfully"
        );
      });