【问题标题】:Chrome notification with rails - 400 UnauthorizedRegistration带有 Rails 的 Chrome 通知 - 400 Unauthorized Registration
【发布时间】:2016-09-12 20:58:12
【问题描述】:

我正在使用 Rails 和 https://github.com/zaru/webpush gem 并根据本指南进行了配置 https://rossta.net/blog/web-push-notifications-from-rails.html

我设法注册 ServiceWorker 并获得订阅。我把它这样保存在控制器中

endpoint = params[:subscription][:endpoint]
p256dh = params[:subscription][:keys][:p256dh]
auth = params[:subscription][:keys][:auth]

current_user.gcm_endpoint = endpoint
current_user.gcm_p256dh = p256dh
current_user.gcm_auth = auth

稍后我会这样发送消息:

message = {
    title: "Title",
    body: "This is a test notification",
    icon: "images/my-128.png"
}

Webpush.payload_send(
    endpoint: current_user.gcm_endpoint,
    message: JSON.generate(message),
    p256dh: current_user.gcm_p256dh,
    auth: current_user.gcm_auth,
    ttl: 600,
    api_key: "<MY API KEY>"
)

我已在 Google 控制台上配置并激活帐户。我已打开 GCM API 并添加了正确的密钥。但无论我做什么,我都会收到这个 400 错误代码。而且我在 Google 控制台中没有统计信息 - 好像没有对我的 API 调用进行调用。

【问题讨论】:

标签: ruby-on-rails ruby google-cloud-messaging web-push chrome-gcm


【解决方案1】:

问题出在密钥本身。需要使用单独的 Firebase 控制面板生成它。 Here 使用该密钥,我的代码运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-04
    • 2018-04-04
    • 1970-01-01
    • 2023-04-08
    • 2016-04-15
    • 1970-01-01
    • 2018-11-22
    • 1970-01-01
    相关资源
    最近更新 更多