这是我向Expo api发出发布请求时收到的api错误:
{"errors":[{"code":"API_ERROR","message":"child \"to\" fails because [\"to\" is required], \"value\" must be an
array."}]}
这是我要提出的要求
$payload=json_encode([
'to' => "ExponentPushToken[xxxxxxxxxxxxxxxx]",
'title'=>'Hello',
'body'=>'hello World',
]);
$response = Http::withHeaders([
'Host'=>'exp.host',
'accept'=>'application/json',
'Content-Type' => 'application/json',
'accept-encoding'=>'grizp,deflate',
])->post('https://exp.host/--/api/v2/push/send', [
'debug' => TRUE,
'body' => $payload,
]);
但是当我使用JavaScript从EXPO应用程序进行api调用时,效果很好
sendPushNotification = async () => {
const message = {
to: this.state.expoPushToken,
sound: 'default',
title: 'Hello',
body: 'Hello World',
data: { data: 'goes here' },
_displayInForeground: true,
};
const response = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
});
};