问题描述
在 node-js 中运行以下行后:
import * as admin from "firebase-admin";import * as serviceAccount from "../../firebase_service_account_key.json";const app = admin.initializeApp({凭据:admin.credential.cert(serviceAccount as any),数据库网址:https://my-app-path.firebaseio.com"});admin.messaging().send({令牌:已知良好的令牌",通知: {title: "测试推送笔记",正文:这是一些文字"}});
我收到错误:
错误:来自 APNS 或 Web 推送服务的身份验证错误原始服务器响应:{错误":{代码":401,"message":"来自 APNS 或 Web 推送服务的身份验证错误","status":"未认证",细节"[{"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError","errorCode":"THIRD_PARTY_AUTH_ERROR"},{"@type":"type.googleapis.com/google.firebase.fcm.v1.ApnsError",状态代码":403,原因":无效提供者令牌"}]}}"
我在 Firebase 的设置">云消息传递"部分下向我的 ios 项目添加了APNs 身份验证密钥".我还正确下载并导入了我的服务帐户 json 文件.
在研究方面,我尝试查找错误.
对于
InvalidProviderToken
错误,添加 APNs 密钥时(上传到云消息传递 > APNs 身份验证密钥):
- 团队 ID(应根据上面的 ios 应用信息自动设置)
- 密钥 ID(通常在密钥的名称中,最好在创建时获取)
After running the following line in node-js:
import * as admin from "firebase-admin"; import * as serviceAccount from "../../firebase_service_account_key.json"; const app = admin.initializeApp({ credential: admin.credential.cert(serviceAccount as any), databaseURL: "https://my-app-path.firebaseio.com" }); admin.messaging().send({ token: "known-good-token", notification: { title: "Test Push Note", body: "Here is some text" } });
I'm getting the error:
Error: Auth error from APNS or Web Push Service Raw server response: "{ "error":{ "code":401, "message":"Auth error from APNS or Web Push Service", "status":"UNAUTHENTICATED", "details"[ { "@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError", "errorCode":"THIRD_PARTY_AUTH_ERROR" }, { "@type":"type.googleapis.com/google.firebase.fcm.v1.ApnsError", "statusCode":403, "reason":"InvalidProviderToken" } ] } }"
I've added an "APNs Authentication Key" to my ios project under the Settings > Cloud Messaging section of Firebase. I've also properly downloaded and imported my service account json file.
In terms of research, I've tried looking up the errors.
For the
InvalidProviderToken
error, this answer seems to indicate I'm using an old token. This is totally possible, but the logs on my app and database appear to match, so it seems off.As for the
THIRD_PARTY_AUTH_ERROR
, google gave me no hits. The closest thing I found was this, and the following text might be the culprit (EDIT: it's not the issue):
Does anyone have anymore details on this error which might help me get to the bottom of it?
解决方案This error arises if your app setup for iOS has an error in any one of the following:
Found in Settings > General > Your Apps > iOS Apps:
- App Store ID
- Bundle ID
- Team ID
When adding an APNs key (Uploading to Cloud Messaging > APNs Authentication Key):
- Team ID (should auto set based off ios app info above)
- Key Id (often is in the name of the key, best to grab when creating it)
这篇关于Firebase 错误:来自 APNS 或 Web 推送服务的身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!