2

尝试使用 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]
                        ]
                    ]);
4

1 回答 1

5

您正在使用form_paramsjson而是像这样使用:

$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]
    ]
]);
于 2019-01-12T08:20:04.123 回答