ruby-on-rails - FCM API 错误请求
问题描述
我正在尝试通过 FCM 从我的 Ruby on Rails 项目中推送通知,这是我的代码:
require 'net/http'
require 'json'
def send_notifications
log = Logger.new("log/notifications.log")
begin
uri = URI.parse("https://fcm.googleapis.com/fcm/send")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
key = '...'
hash = {:notification => {:sound => "default", :title => "test", :text => "test", :badge => "0"}, :data => {:targetID => "1", :to => "..."}}
req = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/json', 'Authorization' => "key=#{key}"})
req.body = hash.to_json
response = http.request(req)
log.debug("response #{response.body}")
rescue => e
log.debug("failed #{e}")
end
end
我收到 Bad Request 400 错误,调试响应正文只显示:“to”
请帮我调试这个问题。谢谢
解决方案
推荐阅读
- java - 关闭并再次单击后如何修复对话框中的错误?
- javascript - 在突变中改变 Vuex 状态会引发“不要在突变之外改变 Vuex 存储状态”
- ios - 如何将文本从 ViewController (iOS) 发送到 InterfaceController (Watch Kit)?
- java - 如何让android应用程序上的所有课程运行
- javascript - 以 mm 为单位计算 svg 路径
- java - 获取特定月份的天数
- javascript - 为什么 axios GET 调用不适用于基本身份验证?
- php - 字符串中仅以空格(或字符串的开头/结尾)为边界的标题大小写单词
- javascript - 删除创建的 div js
- applescript - Applescript - 递归遍历目录