fcm
fcm copied to clipboard
create_notification_key throws Error 500 Internal Server Error
when I run
@fcm = FCM.new(StringIO.new(ENV.fetch('FCM_AUTH_JSON_STRING')), ENV.fetch('FCM_AUTH_SENDER_ID'))
token = "yyyyyyyyyyyyyyyyyyyy:xxxxxxxxxxxxxdevicetoken"
notification_title = "asdf"
notification_body = "asdf"
notification_data_type = nil
message = {
token: token,
# token: fcm_device_group_notification_key,
# 'topic': "yourTopic",
# 'condition': "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)",
data: notification_data_type ? { type: notification_data_type } : nil,
notification: {
title: notification_title,
body: notification_body,
},
}.compact
response_body = @fcm.send_notification_v1(message)
all ok
=> {:body=>"{\n \"name\": \"projects/1003694490304/messages/1727410938098076\"\n}\n",
:headers=>
{"content-type"=>"application/json; charset=UTF-8",
"vary"=>"Origin, X-Origin, Referer",
"date"=>"Fri, 27 Sep 2024 04:22:18 GMT",
"server"=>"scaffolding on HTTPServer2",
"cache-control"=>"private",
"x-xss-protection"=>"0",
"x-frame-options"=>"SAMEORIGIN",
"x-content-type-options"=>"nosniff",
"alt-svc"=>"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"connection"=>"close",
"transfer-encoding"=>"chunked"},
:status_code=>200,
:response=>"success"}
but
os = "ios"
device_registration_ids = [token],
params = {
key_name: "user-#{163}",
project_id: ENV.fetch('FCM_AUTH_SENDER_ID'),
registration_ids: device_registration_ids,
}
response = @fcm.create_notification_key(*params.values)
sometimes gives
=> {:body=>"<HTML>\n<HEAD>\n<TITLE>Internal Server Error</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<!-- GSE Default Error -->\n<H1>Internal Server Error</H1>\n<H2>Error 500</H2>\n</BODY>\n</HTML>\n",
:headers=>
{"content-type"=>"text/html; charset=UTF-8",
"date"=>"Fri, 27 Sep 2024 04:12:58 GMT",
"expires"=>"Fri, 27 Sep 2024 04:12:58 GMT",
"cache-control"=>"private, max-age=0",
"x-content-type-options"=>"nosniff",
"x-frame-options"=>"SAMEORIGIN",
"content-security-policy"=>"frame-ancestors 'self'",
"x-xss-protection"=>"1; mode=block",
"server"=>"GSE",
"alt-svc"=>"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"connection"=>"close",
"transfer-encoding"=>"chunked"},
:status_code=>500,
:response=>"There was an internal error in the FCM server while trying to process the request."}
but more often it gives
{:body=>"<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<!-- GSE Default Error -->\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n",
:headers=>{"content-type"=>"text/html; charset=UTF-8",
"date"=>"Thu, 26 Sep 2024 16:25:31 GMT",
"expires"=>"Thu, 26 Sep 2024 16:25:31 GMT",
"cache-control"=>"private, max-age=0",
"x-content-type-options"=>"nosniff",
"x-frame-options"=>"SAMEORIGIN",
"content-security-policy"=>"frame-ancestors 'self'",
"x-xss-protection"=>"1; mode=block",
"server"=>"GSE",
"alt-svc"=>"h3=\":443\";
ma=2592000,h3-29=\":443\"; ma=2592000",
"connection"=>"close", "transfer-encoding"=>"chunked"},
:status_code=>401,
:response=>"There was an error authenticating the sender account."}
just double checking you have upgraded to the latest version?
- https://github.com/decision-labs/fcm/releases/tag/v2.0.0
- https://rubygems.org/gems/fcm