未收到发送至“/topics/all”的 FCM
FCM sent to "/topics/all" is not received
我已尝试使用以下代码发送 FCM 通知
json_data = {
"to": msg_to,
"notification": {
"body": msg,
"title" : title,
"icon": icon,
"click_action": url
},
}
url = 'https://fcm.googleapis.com/fcm/send'
myKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
data = json.dumps(json_data)
headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % myKey}
req = urllib2.Request(url, data, headers)
f = urllib2.urlopen(req)
发送消息“至”时,我的浏览器没有收到通知:/topics/all
但是,如果我发送带有“to”的消息:我的注册令牌,我会收到通知。
谁能告诉我为什么会这样。我知道发送到 /topics/all 的消息应该到达所有注册用户,并且 all 是默认主题,无需特别订阅。
您似乎假设 clients/tokens 会自动订阅 /topics/all
,但事实并非如此。没有默认主题。
您必须为每个 client/token 订阅该主题,这(在网络客户端的情况下)意味着您必须设置服务器端代码才能安全地执行此操作,如图所示 here.
我已尝试使用以下代码发送 FCM 通知
json_data = {
"to": msg_to,
"notification": {
"body": msg,
"title" : title,
"icon": icon,
"click_action": url
},
}
url = 'https://fcm.googleapis.com/fcm/send'
myKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
data = json.dumps(json_data)
headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % myKey}
req = urllib2.Request(url, data, headers)
f = urllib2.urlopen(req)
发送消息“至”时,我的浏览器没有收到通知:/topics/all
但是,如果我发送带有“to”的消息:我的注册令牌,我会收到通知。
谁能告诉我为什么会这样。我知道发送到 /topics/all 的消息应该到达所有注册用户,并且 all 是默认主题,无需特别订阅。
您似乎假设 clients/tokens 会自动订阅 /topics/all
,但事实并非如此。没有默认主题。
您必须为每个 client/token 订阅该主题,这(在网络客户端的情况下)意味着您必须设置服务器端代码才能安全地执行此操作,如图所示 here.