javascript - Javascript 中 Firebase CLI 函数中的解析错误
问题描述
我正在尝试使用 Firebase Cloud Messaging 服务和 Fireabse CLI 中的代码从 android 设备发送一对一的通知。但是由于解析错误,我无法部署代码,我无法弄清楚。
我的想法如下:出于安全原因,我理解,我需要使用 Firebase Cloud 功能来发送通知。从我的 android 代码中,我将在 Firebase 数据库中编写目标设备的令牌、消息正文和主题。一旦 write 事件发生,Firease 函数就会被部署来发送通知。这是我的 Firebase 代码
'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notification/{receiver_token}/{message_topic}/{message_body}’).onWrite((data, context) =>
{
const receiver_token = context.params.receiver_token;
const message_topic = context.params.message_topic;
const message_body = context.params.message_body;
console.log('We have a notification to send to token: ’ , receiver_token);
const payload =
{
notification:
{
title: message_topic,
body: message_body,
icon: "default"
}
};
return admin.messaging().sendToDevice(receiver_token, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
当我尝试在 Firebase 中部署此功能时,出现以下错误:
错误解析错误:未终止的字符串常量错误:函数预部署错误:命令以非零退出代码1终止
如果需要,我可以提供完整的错误日志
解决方案
这行代码看起来像一个问题:
console.log('We have a notification to send to token: ’ , receiver_token);
您的开头引号是单引号(撇号),但您的结尾引号是不同的引号。非常仔细地观察它们。使第二个匹配第一个。
推荐阅读
- snowflake-cloud-data-platform - 使用雪花中的计划任务来克隆具有动态名称的数据库
- networking - 即使端口被转发,udp 连接客户端也不会收到本地网络之外的消息
- django - 如何在 Windows 上运行 django 项目(在 linux 上制作)?
- azure-data-factory-2 - ADF json 表达式格式化
- scala - IntelliJ Scala:导入在测试文件夹中有效,但不在主文件夹中
- c# - SQL 和 C# 错误:SQL 过程出错:将数据类型 nvarchar 转换为日期时间时出错
- python - Pandas groupby 和连接字符串
- android - 我们如何从 android 代码库构建 android ndk
- c# - 在任务计划程序中运行的程序无法获取注册表值
- javascript - 为什么现在不给我的 Unix 时间戳添加 24 小时的秒数?