简体   繁体   English

firebase messenger.getToken() 返回 null

[英]firebase messaging.getToken() return null

I am following this tutorial Set Up a JavaScript Firebase Cloud Messaging Client App .我正在关注本教程设置 JavaScript Firebase 云消息传递客户端应用程序 When I ran the page for the first time, I clicked on "Block" rather than "Allow" when the page asked me to show notifications.当我第一次运行页面时,当页面要求我显示通知时,我点击了“阻止”而不是“允许”。 After removing the site from the Chrome blocked list Turn notifications on or off , messaging.getToken() always returns null .从 Chrome 阻止列表中删除站点后打开或关闭通知messaging.getToken()始终返回null

I tried messaging.deleteToken() but this requires a valid (not null) token anyway.我尝试过messaging.deleteToken()但这无论如何都需要一个有效的(非空)令牌。

How to solve this?如何解决这个问题?

You must start a server in the folder of your project您必须在项目文件夹中启动服务器

php -S 127.0.0.1:8080

and access like this http://127.0.0.1:8080/并像这样访问http://127.0.0.1:8080/

It will NEVER work if you sign in from another folder like this http://127.0.0.1/miproyecto/ http://localhost/myproject/如果您从像这样的另一个文件夹登录http://127.0.0.1/miproyecto/ http://localhost/myproject/ ,它将永远不会工作

remember to create the file firebase-messaging-sw.js in the root https://firebase.google.com/docs/cloud-messaging/js/receive?hl=en-419记得在根https://firebase.google.com/docs/cloud-messaging/js/receive?hl=en-419 中创建文件 firebase-messaging-sw.js


Debes iniciar un servidor en la carpeta de tu proyecto Debes iniciar un servidor en la carta de tu proyecto

php -S 127.0.0.1:8080

y acceder así http://127.0.0.1:8080/ y 加入http://127.0.0.1:8080/

NUNCA funcionara si accedes desde otra carpeta así http://127.0.0.1/miproyecto/ http://localhost/miproyecto/ NUNCA funcionara si 加入 desde otra 地毯 así http://127.0.0.1/miproyecto/ http://localhost/miproyecto/

recuerda crear el archivo firebase-messaging-sw.js en la raiz https://firebase.google.com/docs/cloud-messaging/js/receive?hl=es-419 recuerda crear el archivo firebase-messaging-sw.js en la raiz https://firebase.google.com/docs/cloud-messaging/js/receive?hl=es-419

  1. Click "View site information" icon单击“查看站点信息”图标
  2. Set Notification to "Allow" Allow Notification将通知设置为“允许”允许通知
  3. Click on Cookies单击 Cookie
  4. Select the host name (localhost in my case) remove cookies选择主机名(在我的情况下为 localhost)删除 cookie
  5. Click on Remove点击移除
  6. Click on Done点击完成

Don't forget to make a firebase-messaging-sw.js file in your root repo or public folder inside root repo .不要忘记在root reporoot repo 内的公共文件夹中创建 firebase-messaging-sw.js文件。 And then, open that file via your localhost server.然后,通过本地主机服务器打开该文件。 Ex : localhost:5000/firebase-messaging-sw.js .例如: localhost:5000/firebase-messaging-sw.js

If you still get an error page, you need to create manifest.json file.如果仍然出现错误页面,则需要创建manifest.json文件。 In this file, put your gcm_sender_id or messagingSenderID .在这个文件中,把你的gcm_sender_idmessagingSenderID。

{
     "gcm_sender_id" : "587997283287" 
}

In my case, I can resolve this problem.就我而言,我可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:messaging.getToken 不是 function - TypeError: messaging.getToken is not a function WebPush PushSubscription 与 messages.getToken? - WebPush PushSubscription vs messaging.getToken? 为什么我的 messages.getToken() 在 Firefox 中有效,但在 chrome 中无效? - Why my messaging.getToken() works in firefox but not in chrome? 为什么Messaging.getToken()不能在服务工作者范围内使用 - Why messaging.getToken() cannot be used in service worker scope Firebase 云消息传递 - JS SDK 中的 getToken() 错误 - Firebase Cloud Messaging - getToken() error in JS SDK Chrome扩展程序中Firebase Cloud Messaging的getToken()待处理 - Firebase Cloud Messaging's getToken() pending in Chrome Extension firebase.messaging.getToken() 在 Google Chrome 上无法按预期工作 - firebase.messaging.getToken() not working as expected on Google Chrome Firebase JS - getToken()不返回令牌 - Firebase JS - getToken() does not return a token 每次刷新使用Firebase Cloud Messaging + React和firebase.messaging()。getToken()都是不同的 - Using Firebase Cloud Messaging + React and firebase.messaging().getToken() is different each refresh 调用 firebase.messaging.getToken() 时出现“请求缺少身份验证凭据”错误 - "Request is missing authentication credential" error when calling firebase.messaging.getToken()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM