google-chrome - Web Push API Chrome,返回 "Unauthorized Registration"

标签 google-chrome push-notification google-cloud-messaging web-push

我一直在做 google tutorial关于如何使用 web-push 节点模块在 Chrome 上发送网络推送通知。

问题是,教程还提供了一个 companion server app您应该使用它来测试从服务器向客户端发送推送通知。

但是,在配套应用程序中,甚至在我的本地计算机上使用 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' }

最佳答案

您是否使用过任何 HTTP 服务器来测试该教程中的代码?此外,DNS 应该是 本地主机 https://地点。如果您在某个端口下运行 HTTP 服务器,最好使用 5 位客户端端口。这里链接了我的项目browser push

关于google-chrome - Web Push API Chrome,返回 "Unauthorized Registration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40801235/

相关文章:

ios - 推送通知参数本地化

android - 获取移动应用程序(Android 或 iOS)的 facebook 流更新

javascript - JSFiddle 代码在我自己的页面中不起作用

php - 使用 PHP 的 GCM 实现总是面临未经授权的错误 401

xmpp - 使用 Smack 4.1.0 的 GCM XMPP 服务器

android - 将自定义JAR库添加到Android项目时,Delphi10.2中出现编译器错误

android - GCM 无效发件人错误

javascript - 如何在 Chrome 中禁用平滑滚动

java - 如何用 Selenium 向右或向左滑动?

html - 为什么 Chrome 没有正确考虑边距?