提供的主题值无效

编程入门 行业动态 更新时间:2024-10-27 19:17:34
本文介绍了提供的主题值无效-将FCM发送到主题时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试向主题发送FCM消息.但是从服务器收到提供了无效的主题值"错误.

I am trying to send an FCM message to a topic. But getting "Invalid topic value provided" error from the server.

Json有效载荷

{ "message":{ "topic":"/topics/news", "data":{ "title":"Hellow World", "message":"This is the Topic Message", "type1":"100", "type2":"abc" } } }

响应

{ "error":{ "code":400, "message":"Request contains an invalid argument.", "status":"INVALID_ARGUMENT", "details":[ { "@type":"type.googleapis/google.rpc.BadRequest", "fieldViolations":[ { "field":"message.topic", "description":"Invalid topic value provided." } ] }, { "@type":"type.googleapis/google.firebase.fcm.v1.FcmError", "errorCode":"INVALID_ARGUMENT" } ] } }

我尝试将主题值设置为新闻"(不带'/topics/'),但会引发相同的错误.我可以从Firebase控制台将消息发送到该主题,而不会出现任何问题.

I have tried topic value as "news" (without '/topics/') but it throws same error. I can send message to the topic from firebase console without any problem.

任何帮助表示赞赏. TIA

Any help appreciated. TIA

Edit1-下面的通知有效负载工作正常,但数据有效负载不起作用.根据文档,也允许数据有效载荷 firebase.google /docs/cloud-messaging/android/topic-messaging 请求

Edit1 - Notification payload below works fine but data payload doesn't work. As per documentation, data payloads too are allowed firebase.google/docs/cloud-messaging/android/topic-messaging Request

{ "message":{ "topic" : "foo-bar", "notification" : { "body" : "This is a Firebase Cloud Messaging Topic Message!", "title" : "FCM Message", } } }

这行得通.我的代码中有一个小错误,该错误为该主题添加了其他引号.下面的请求就像一个魅力

EDIT2 : This works. I had a small bug in my code which was adding additional quotes to the topic. Below request works like a charm

{ "message":{ "topic":"news", "data":{ "title":"Hellow World", "message":"This is the Topic Message", "type1":"100", "type2":"abc" } } }

推荐答案

根据 doc 您的请求应如下所示:

according to doc yor request should be like this:

fcm.googleapis/fcm/send Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA { "to": "/topics/foo-bar", "data": { "message": "This is a Firebase Cloud Messaging Topic Message!", } }

更多推荐

提供的主题值无效

本文发布于:2023-10-11 22:16:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1482994.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!