如何在新 Onesignal React-native 中添加 header

How to add header in new Onesignal React-native

 Error: {"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"]}

我试过如下但错误如上

sendNotification = async (data) => {

    const { userId } = await OneSignal.getDeviceState();
    const notificationObj = {
      contents: { en: "Message Body" },
      include_player_ids: [userId],
      Authorization: "Basic APIKEY",
      headings: { en: 'You have new notification' },
      android_channel_id: 'id',
      template_id: 'id',
      buttons: [{ "id": "open_flat", "text": "OPEN HOSTING", "icon": "ic_menu_share" }],
      include_external_user_ids: ["13245-123455"],
    };

    const jsonString = JSON.stringify(notificationObj);

    OneSignal.postNotification(jsonString, (success) => {
      console.log("Success:", success);
    }, (error) => {
      console.log("Error:", error);
    });
      };

    //Sending demo 
    useEffect(() => {
        sendNotification()
      })

我收到错误: 错误:{“错误”:[“请包含授权的 case-sensitive header:具有有效 REST API 密钥的基本。”],“参考”:[“https:// documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"]}

几个月来我尝试发送带有内容类型和授权的获取通知header

您需要将 APIKEY 替换为您实际的 API 密钥,例如您的 API 密钥是“MY_API_KEY123456”,那么 header 应该是授权:“基本 MY_API_KEY123456”

任何人都有这个错误

 let headers = {
    'Content-Type': 'application/json; charset=utf-8',
    Authorization: `Basic '<API-KEY-HERE>'`,
};
let endpoint = 'https://onesignal.com/api/v1/notifications';
let params = {
    method: 'POST',
    headers: headers,
    body: JSON.stringify({
        app_id: 'App Id',
        include_external_user_ids: [{'userid'},{'userid2'}], --> Optional
        headings: { en: 'DATA'},
        contents: { en: 'DATA'},
        buttons: [{ "id": 'id', "text": 'OPEN', "icon": "ic_baseline_open_in_new_24" }], --> OPTIONAL
        data: 'Extra data as json'

    }),
};
fetch(endpoint, params).then(res => { console.log('sucess NotiButton') }).catch(error => console.log('error' + error));