MNa*_*sar 2 node.js firebase google-cloud-functions firebase-cloud-messaging
简而言之,我想使用 Google Cloud Functions 向订阅主题组合的设备发送通知。
\n\n文档说:
\n\n\n\n\n“主题中的\'TopicA\' &&(主题中的\'TopicB\' || 主题中的\'TopicC\')”
\n
我试图做的是:
\n\nvar topicsConditions = `\'${type}\' in topics && (\'${area}\' in topics || \'${city}\' in topics)`;\n\n// Send a message to devices subscribed to the provided topic.\nadmin.messaging().sendToCondition(topicsConditions, notificationPayload)\n .then(function(response) {\n // See the MessagingTopicResponse reference documentation for the\n // contents of response.\n console.log("Successfully sent message:", response);\n })\n .catch(function(error) {\n console.log("Error sending message:", error);\n });\nRun Code Online (Sandbox Code Playgroud)\n\n但我不断收到此错误:
\n\n\n\n\n发送消息时出错:{ 错误:提供的参数无效。原始服务器响应:“无效的“条件”字段:仅支持\'主题\'条件\n”。状态代码:400。\n 位于 FirebaseMessagingError.Error(本机)\n 位于 FirebaseMessagingError.FirebaseError [作为构造函数] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)\n 位于 FirebaseMessagingError .PrefixedFirebaseError [作为构造函数] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)\n 在新的 FirebaseMessagingError (/user_code/node_modules/firebase-admin/lib/utils/error.js :241:16)\n 在 /user_code/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:115:23\n 在 process._tickDomainCallback (internal/process/next_tick.js:135:7 )\n errorInfo: \n { code: \'messaging/invalid-argument\',\n message: \'提供的参数无效。原始服务器响应:“无效的“条件”字段:仅支持\\\'主题\\\'条件\\n”。状态代码: 400.\' },\n codePrefix: \'messaging\' }
\n
任何人都可以指导我正确的语法吗?
\n\n编辑:主题的日志输出为:
\n\n\n\n主题条件=主题中的\'MyType+\' && (主题中的\'埃及吉萨\'|| \'\xd8\xa7\xd9\x84\xd9\x82\xd8\xa7\xd9\x87\xd8\xb1\ xd8\xa9 \xd8\xa7\xd9\x84\xd9\x83\xd8\xa8\xd8\xb1\xd9\x89\' 中的主题)
\n
主题名称中可以使用的字符仅限于:
a至zA至Z0到9- _ . ~ %您的主题名称包含无效字符+、,、空格和阿拉伯语。
更多详细信息请参阅文档:
开发者可以选择任何符合正则表达式的主题名称:“[a-zA-Z0-9-_.~%]+”
有效条件字符串的示例是:
var topicsConditions = "'Aswan' in topics && ('Giza' in topics || 'Cairo' in topics)";
Run Code Online (Sandbox Code Playgroud)
我成功地在调用中使用了这个字符串admin.messaging().sendToCondition()
| 归档时间: |
|
| 查看次数: |
2653 次 |
| 最近记录: |