尝试发送消息时,Firebase Cloud Functions返回错误

时间:2019-01-06 13:38:07

标签: node.js firebase firebase-cloud-messaging google-cloud-functions firebase-admin

当Firestore中的某些事件被触发时,我正在使用Firebase Cloud Functions向用户发送通知。下面的示例代码在一段时间之前可以正常工作,但是现在当我尝试运行此代码时出现错误

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

admin.initializeApp();

export const onGenderChange = functions.firestore.document('users/fOZFJvfDwhXCFnXjyWtlEYcf2kM2').onUpdate((change, context) => {
    const message = {
        data: {
            time: 'a',
            score: 'b',
            click_action: 'FLUTTER_NOTIFICATION_CLICK'
        },
        token: 'e1P2KLrNNss:APA91bH4b__7VA-QpUMSPCKMcG91TITF8B23CMYWkyfAcnleCbJfA3QPyhLNJABDm8KHlNmNBGAN48UiNQ67yoCrRLXqXqfH0OhJR5RwNHstFq1gEmXxGR-aUrxf5PWyrQrjk7D3m__n'
    };
    return admin.messaging().send(message);
});

错误信息:

Error: Requested entity was not found.
    at FirebaseMessagingError.Error (native)
    at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
    at new FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
    at Function.FirebaseMessagingError.fromServerError (/user_code/node_modules/firebase-admin/lib/utils/error.js:271:16)
    at FirebaseMessagingRequestHandler.handleHttpError (/user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:125:50)
    at /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:113:23
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

功能已触发,令牌有效,因为我可以从Firebase控制台手动向该用户发送通知。 是什么导致此错误? Cloud Functions项目的配置错误,版本错误或其他原因?

0 个答案:

没有答案