【发布时间】:2021-11-30 16:45:35
【问题描述】:
我想使用 zoom API 创建一个网络研讨会活动,我使用 php 创建正文数据并在 json_encode 中格式化 json,但是当我将 POST 发送到 zoom API 时它不起作用。结果总是这样:
[
[code] => 300
[message] => Request Body should be a valid JSON object.
]
这是我在控制器中的代码:
$id = Yii::$app->request->get('id');
$bodyparam = [
"topic" => "test webinar",
"type" => 5,
"start_time" => "2021-10-02T16:00:00Z",
"duration" => 60,
"timezone" => "Asia/Singapore",
"password" => "test123456",
"agenda" => "Test Webinar",
"recurrence" => [
"type" => 1,
"repeat_interval" => 1,
"end_date_time" => "2021-10-02T16:00:00Z"
],
"settings" => [
"host_video" => true,
"panelists_video" => true,
"practice_session" => true,
"hd_video" => true,
"approval_type" => 0,
"registration_type"=> 2,
"audio" => "both",
"auto_recording" => "none",
"enforce_login" => false,
"close_registration" => true,
"show_share_button" => true,
"allow_multiple_devices" => false,
"email_language" => "en-US",
"panelists_invitation_email_notification" => true,
"registrants_confirmation_email" => true,
"registrants_email_notification" => true,
"attendees_and_panelists_reminder_email_notification" => [
"enable" => true,
"type" => 1
],
"follow_up_attendees_email_notification" => [
"enable" => true,
"type" => 1
],
"follow_up_absentees_email_notification" => [
"enable" => true,
"type" => 1
]
]
];
//using json_decode and double encode because if i just encode once the result always string
$body = json_encode(json_decode(json_encode($bodyparam)), JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
$response = Yii::$app->zoom->doRequest('POST','/users/'.$id.'/webinars',['status'=>'active'], $body);
echo "<pre>";print_r($response);exit;
我使用skwirrel zoom api 包装器来帮助我创建这个事件。有什么问题吗?
【问题讨论】:
-
问:有什么问题吗?答:是的。服务器说有效载荷不是有效的 JSON。建议:在发送之前回显 $body。 Edit 您的帖子带有正在传输的实际 JSON。您还可以将您的 PHP“echo”复制/粘贴到验证器中,例如 jsonlint.com
-
我想你只需要做
$body = json_encode($bodyparam); -
结果是
valid JSON,然后呢? -
@Dula 我试过了,但还是
Request Body should be a valid JSON object.