Firebase Web应用(Web Push API等)调用getToken报token-unsubscribe-failed
Firebase Web应用在浏览器(Web Push API等场合)调用:
getToken(messaging, { serviceWorkerRegistration: swr, vapidKey: publicKey });
控制台报错: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). DELETE 404
原文如下:
It turns out that new versions of Firebase SDKs depend on a new internal infrastructure service, called FIS (the Firebase Installations Service) for targeting identifiers ("FIDs" or "Instance-IDs"). If you are using API key restrictions for the API keys you use in your application, you will have to extend those restrictions to allow usage with the new Firebase Installations Service at firebaseinstallations.googleapis.com.
To allow your API key in question to be used with the new Firebase Installations API:
- go to the Google Cloud Console
- choose the relevant project (i.e. the project you use for your application)
- open the menu and go to APIs & Services -> Credentials
- click Edit API key for the API key in question
- scroll down to API restrictions
- from the dropdown, choose: FCM Registration API、Firebase Installations API、Firebase Cloud Messaging API、Firebase Management API、Firebase Remote Config API
- click Save
- wait a couple of minutes for Google servers to update and retry...
总体来说,就是到GCP控制台的“API 和服务->凭据”中限制下API用途范围。