【问题标题】:status 300 after sending POST API to zoom发送 POST API 到缩放后的状态 300
【发布时间】: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.

标签: php rest zoom-sdk


【解决方案1】:

根据文档,您必须传递一个数组作为doRequest() 方法的第三个参数。不是 JSON 字符串。

$response = $zoom->doRequest(<METHOD>, <endpoint_path> [,<query_parameter_array> [,<path_parameter_array> [,<request_body_array_or_string>] ] ]);

简化:

$params = [,<path_parameter_array> [,<request_body_array_or_string>] ] ];
$response = $zoom->doRequest('METHOD','ENDPOINT_PATH',$params);

看看this example

【讨论】:

  • 我试了一下还是不行
  • 这应该可以。 $response = Yii::$app-&gt;zoom-&gt;doRequest('POST','/users/'.$id.'/webinars',array(),array(),json_encode($bodyparam));
  • 还是不行:(
  • 您是否遇到任何错误?
  • 不,还是返回Request Body should be a valid JSON object
猜你喜欢
  • 2020-07-18
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多