尝试使用Guzzle向SendBird API发送请求时收到错误消息。
错误消息
"message": "Client error: `POST https://api.sendbird.com/v3/group_channels` resulted in a `400 BAD REQUEST` response:\n{\"message\":\"Not valid JSON body.\",\"code\":400403,\"error\":true}\n",
"exception": "GuzzleHttp\\Exception\\ClientException",
我的代码
$client = new Client([
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer XXXXX',
'Content-Type' => 'application/json',
],
]);
$response = $client->post('https://api.sendbird.com/v3/group_channels', [
'form_params' => [
'user_ids' => [$user_id_1,$user_id_2],
'operator_ids' => [$user_id_1,$user_id_2]
]
]);
答案 0 :(得分:3)
您正在使用form_params,请改用json,如下所示:
$response = $client->post('https://api.sendbird.com/v3/group_channels', [
'json' => [
'user_ids' => [$user_id_1, $user_id_2],
'operator_ids' => [$user_id_1, $user_id_2]
]
]);