Web Push API Chrome,返回“未经授权的注册”

12
我一直在做一个谷歌教程,教如何使用web-push node模块在Chrome上发送网页推送通知。
问题在于,该教程还提供了一个配套的服务器应用程序,你应该使用它来测试从服务器向客户端发送推送通知。
但是,在使用配套应用程序或者在本地机器上使用web-push cli时,当尝试发送通知时,我会收到"未经授权的注册"错误。
网络上找不到有关此错误的任何信息 - 我做错了什么/遗漏了什么?
$ web-push send-notification --endpoint=https://fcm.googleapis.com/fcm/send/<<endpoint-key>>
Error sending push message:
{ [WebPushError: Received unexpected response code]
  name: 'WebPushError',
  message: 'Received unexpected response code',
  statusCode: 400,
  headers:
   { 'content-type': 'text/html; charset=UTF-8',
     date: 'Fri, 25 Nov 2016 08:54:08 GMT',
     expires: 'Fri, 25 Nov 2016 08:54:08 GMT',
     'cache-control': 'private, max-age=0',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'SAMEORIGIN',
     'x-xss-protection': '1; mode=block',
     server: 'GSE',
     'alt-svc': 'quic=":443"; ma=2592000; v="36,35,34"',
     'accept-ranges': 'none',
     vary: 'Accept-Encoding',
     connection: 'close' },
  body: '<HTML>\n<HEAD>\n<TITLE>UnauthorizedRegistration</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>UnauthorizedRegistration</H1>\n<H2>Error 400</H2>\n</BODY>\n</HTML>\n' }

你能解决这个问题吗? - michaeltintiuc
试试这个库:https://github.com/emretekince/fcm-web-push - Emre Tekince
1
对我来说,事实似乎是:https://dev59.com/GZ7ha4cB1Zd3GeqPlJB7#42023959 - pesho hristov
3个回答

1

你在那个教程中使用过任何HTTP服务器进行代码测试吗?此外,DNS应该是localhosthttps://网站。如果您正在某个端口下运行HTTP服务器,则最好具有5位数字的客户端端口。这里链接了我的项目浏览器推送


0

感谢您指出GH问题!不幸的是,重置时钟并不能真正解决问题。 - maephisto

0

请检查您的 manifest.json 文件中的 gcm_sender_id 字段是否与您在Google帐户中的 gcm_sender_id 完全匹配。我之前遇到过类似的问题,这是解决我的问题的方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接