【发布时间】:2021-01-25 16:45:48
【问题描述】:
我正在尝试从 firebase 函数中发送 FCM,但每次都收到以下错误:
await admin.messaging().sendToDevice(registrationToken, message)
我听从了this post, of the same topic 的建议,没有任何帮助。指向文章中的另一个链接 Add the Firebase Admin SDK to your server 并不是很有帮助,因为我正在使用 Firebase Server。
这篇文章,同样,Sending FCM using Firebase Functions 和我使用相同的代码(FCM 代码),同样的错误。
这是完整的错误:
Error sending message: { Error: An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions. Raw server response: "<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
". Status code: 401.
at FirebaseMessagingError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:43:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:89:28)
at new FirebaseMessagingError (/workspace/node_modules/firebase-admin/lib/utils/error.js:255:16)
at Object.createFirebaseError (/workspace/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:57:12)
at /workspace/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:78:51
at process._tickCallback (internal/process/next_tick.js:68:7)
errorInfo:
{ code: 'messaging/authentication-error',
message:
'An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions. Raw server response: "<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n". Status code: 401.' },
codePrefix: 'messaging' }
【问题讨论】:
标签: firebase firebase-cloud-messaging