首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >分析错误:意外的标记click_action

分析错误:意外的标记click_action
EN

Stack Overflow用户
提问于 2019-11-06 03:57:36
回答 2查看 93关注 0票数 0

目前,我正在使用firebase-cloud-messaging处理推送通知。令牌click_action仍然受支持,但我仍然收到此错误。我的代码是,

cmd (Firebase CLI)上的错误是,

代码语言:javascript
运行
复制
notification: {
    title: "Notification from" + from_name,
    body: from_message,
    sound: "default"
    click_action: "com.example.tysf_trial"
}

部署时会遇到此错误,

代码语言:javascript
运行
复制
 43:5  error  Parsing error: Unexpected token click_action

? 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\abc\AppData\Roaming\npm-cache\_logs\2019-11-05T19_43_05_08
1Z-debug.log
events.js:187
      throw er; // Unhandled 'error' event
      ^

Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT
    at notFoundError (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mfirebase
-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←[24m\li
b\enoent.js:6:26)
    at verifyENOENT (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mfirebase-
tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←[24m\lib
\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mf
irebase-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←
[24m\lib\enoent.js:27:25)
←[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess.cp.emit (C:\Users\abc\AppData\Roaming\npm\node_modules\←[4mf
irebase-tools←[24m\node_modules\←[4mcross-env←[24m\node_modules\←[4mcross-spawn←
[24m\lib\enoent.js:30:37)
←[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:1
2)←[39m {
  code: ←[32m'ENOENT'←[39m,
  errno: ←[32m'ENOENT'←[39m,
  syscall: ←[32m'spawn npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
  path: ←[32m'npm --prefix "%RESOURCE_DIR%" run lint'←[39m,
  spawnargs: []
}
EN

回答 2

Stack Overflow用户

发布于 2019-11-27 22:54:45

这是我的黑洞工作代码,它昨天和我一起工作。^_^

代码语言:javascript
运行
复制
    'use-strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.sendNotification = functions.firestore.document
("NotifyUsers/{user_id}/Notification/{notification_id}")
.onWrite((change, context) => {

const user_id = context.params.user_id;
const notification_id = context.params.notification_id;


return admin.firestore().collection("NotifyUsers")
.doc(user_id).collection("Notification").doc(notification_id)
.get().then(queryResult => {

    const {from:from_user_id, message:from_message} = queryResult.data();


    const from_data = admin.firestore().collection("NotifyUsers")
    .doc(from_user_id).get();
    const to_data = admin.firestore().collection("NotifyUsers")
    .doc(user_id).get();


    return Promise.all([from_data, to_data, from_message , from_user_id]);
    // added from_message so it's available in the next .then
})
.then(([from_data, to_data, from_message, from_user_id]) => { // added from_message

    const from_name = from_data.data().name;

    const {name:to_name, token_id} = to_data.data();

    console.log("From: " + from_name + " | To : " + to_name +"from:" +from_user_id);

    const payload = {
        "notification" : {
            "title" : "Notification From : " + from_name,
            "body" : from_message,
            "icon" : 'default',
            "click_action": 'return.to.NotificationActivity'
        },
        "data": {
            "from_user_id" : from_user_id, 
            "message" : from_message
        }
    };

    return admin.messaging().sendToDevice(token_id, payload);
})
.then(result => {
    return console.log("Notification Sent");
});
});
票数 0
EN

Stack Overflow用户

发布于 2019-11-26 03:13:44

sound:行后缺少逗号:

代码语言:javascript
运行
复制
notification: {
    title: "Notification from" + from_name,
    body: from_message,
    sound: "default", // here
    click_action: "com.example.tysf_trial"
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58718578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档