我發現 FCM Web 客戶端偶爾會向我提供不同的令牌。
我的代碼完全基于官方檔案。
// Get registration token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache.
messaging.getToken({ vapidKey: '<YOUR_PUBLIC_VAPID_KEY_HERE>' }).then((currentToken) => {
if (currentToken) {
// Send the token to your server and update the UI if necessary
// Occasionally, I received a different token here.
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
有時,我會收到不同的currentToken; 這經常發生!
我沒有更改我的網路瀏覽器 (Chrome),也沒有更改 vapidKey,我繼續使用相同的選項卡進行本地主機開發。
似乎每隔幾個小時就會改變一次。
如果令牌更改,我的服務作業者將在控制臺中記錄錯誤,以及 404 API 請求失敗。
控制臺日志錯誤如下:
FirebaseError: Messaging: A problem occurred while unsubscribing the user from FCM: FirebaseError: Messaging: A problem occurred while unsubscribing the user from FCM: Requested entity was not found. (messaging/token-unsubscribe-failed). (messaging/token-unsubscribe-failed).
at _callee8$ (eval at <anonymous> (app.js:2982), <anonymous>:572:45)
at tryCatch (eval at <anonymous> (app.js:6025), <anonymous>:62:40)
at Generator.invoke [as _invoke] (eval at <anonymous> (app.js:6025), <anonymous>:296:22)
at Generator.prototype.<computed> [as next] (eval at <anonymous> (app.js:6025), <anonymous>:114:21)
at step (eval at <anonymous> (app.js:636), <anonymous>:17:30)
at eval (eval at <anonymous> (app.js:636), <anonymous>:28:13)
這是我認為 FCM 試圖提出的失敗的 API 請求;我沒有提出請求,而是將其復制為 curl 以獲得更高的可見性。
curl 'https://fcmregistrations.googleapis.com/v1/projects/chatisfy-d2721/registrations/cD0VOZLBLdaVymfaUbQyE4:APA91bHj2qCU02_Sib6gEPw3VuPTDkjpj0ZVpgmWYaaHESpTjpH-uwY5JX5mn_W7YhJ1AOMp4dNnwpUffs7SQkBs1UYGGie0o4u_i-OjYY5Q5uRSl3pZQoRGVzwNXxe0lDrQIHD4SN5A' \
-X 'DELETE' \
-H 'authority: fcmregistrations.googleapis.com' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H 'x-goog-api-key: AIzaSyDFP12b-P9JwiDvJuqsWVz6k2Z8ww6_2-E' \
-H 'x-goog-firebase-installations-auth: FIS eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6IjE6NTI4MTcxMTk2MzYxOndlYjowMWQyMzQ4ODNiYWQ3NWU5MmYxMjE4IiwiZXhwIjoxNjQwMjUwMDc2LCJmaWQiOiJjRDBWT1pMQkxkYVZ5bWZhVWJReUU0IiwicHJvamVjdE51bWJlciI6NTI4MTcxMTk2MzYxfQ.AB2LPV8wRQIhAL4F96JV_fSn2LHzpBiYDWnOVcpA7zBT35lvWz0WqS8fAiAlC28Un0hO2uD6_DuRPnHdqnO_5wIr-byID127niFXRg' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'origin: http://localhost:8080' \
-H 'x-client-data: CJO2yQEIpbbJAQjBtskBCKmdygEInvnLAQjmhMwBCLWFzAEIy4nMAQjSj8wBGI6eywE=' \
-H 'sec-fetch-site: cross-site' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-dest: empty' \
-H 'referer: http://localhost:8080/' \
-H 'accept-language: en-US,en;q=0.9,zh-TW;q=0.8,zh;q=0.7,zh-CN;q=0.6' \
--compressed
這是對上述請求的回應:
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
}
這是什么原因造成的?
uj5u.com熱心網友回復:
某些安全模型會定期過期并重新頒發令牌,以防止令牌長期有效。或者令牌可能包含根據請求時間更新的資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/386104.html
標籤:火力基地 firebase-cloud-消息 渐进式网络应用程序 服务人员 网络推送
上一篇:Firestore-云功能-獲取洗掉檔案的用戶的uid
下一篇:型別錯誤:listingsRef.add不是函式。(在“listingsRef.add(updatedUploadObjects)”中,“listingsRef.add”未定義)
