作为新手开发人员,我正在为我制作一个应用程序,我希望用户使用我的应用程序中的 onesignal postNotificationWithJson(和过滤器)功能按设备上的位置发送通知,但我收到一个错误,我一直在处理这个问题错误 2 天,但我还没有找到解决方案。
错误:
OneSignalRestClient: POST RECEIVED JSON: {"errors":["Please include a case-sensitive header of Authorization: Basic \u003cYOUR-REST-API-KEY-HERE\u003e with a valid REST API key."],"reference":["https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"]}
W/OneSignal( 7314): HTTP code: 400 create notification failed
E/flutter ( 7314): [ERROR:flutter/lib/ui/ui_dart_state.cc(184)] Unhandled Exception: PlatformException(OneSignal, Encountered an error attempting to post notification: {"errors":["Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."],"reference":["https:\/\/documentation.onesignal.com\/docs\/accounts-and-keys#section-keys-ids"]}, {reference: [https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids], errors: [Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key.]}, null)
代码(删除过滤器行时错误消失。):
var response = await OneSignal.shared.postNotificationWithJson({
"Authorization":
"Basic xxxxx",
"filters": [
{
"field": "location",
"lat": "36.1185207",
"long": "36.2526271",
"radius": "800",
}
],
"headings": {"en": "APP NAME"},
"contents": {"en": "Click for more information."},
"data1": {"name": "Markos", "LastName": "Baslik"},
"data2": {"idName": "KNARNYR"},
});