Eventbrite批处理端点 - 您传递了未使用JSON格式的请求体
问题描述:
我的JSON低于该值,验证正确(数字是虚拟数字!)。该字符串被分配给变量$payload
。Eventbrite批处理端点 - 您传递了未使用JSON格式的请求体
[{
"method": "GET",
"relative_url": "series/4/events/?expand=ticket_classes"
}, {
"method": "GET",
"relative_url": "series/5/events/?expand=ticket_classes"
}, {
"method": "GET",
"relative_url": "series/6/events/?expand=ticket_classes"
}, {
"method": "GET",
"relative_url": "series/7/events/?expand=ticket_classes"
}, {
"method": "GET",
"relative_url": "series/8/events/?expand=ticket_classes"
}, {
"method": "GET",
"relative_url": "series/9/events/?expand=ticket_classes"
}]
我的PHP如下:
$url = "https://www.eventbriteapi.com/v3/batch/?token=".$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
curl_setopt($ch, CURLOPT_POST, 1);
$body = \curl_exec($ch);
curl_close($ch);
$json = \json_decode($body,true);
echo $body;
回声吐出:
{"status_code": 400, "error_description": "You passed a request body that was not in JSON format.", "error": "INVALID_BODY"}
似乎一切都很好 - 我一个失去了一些东西明显?
当我通过https://www.eventbriteapi.com网站传递数据,为每一个我得到的只是有分页细节,没有事件的详细信息身体反应...
感谢
答
编辑HTTPClient.php
替换此:
$options = array(
'http'=>array(
'method'=>$httpMethod,
'header'=>"content-type: application/json\r\n",
'content'=>$data,
'ignore_errors'=>true
)
);
有了这个:
$options = array(
'http'=>array(
'method'=>$httpMethod,
'header'=>"content-type: application/json\r\n",
'ignore_errors'=>true
)
);
if ($httpMethod == 'POST') {
$options['http']['content'] = $data;
}
参考:https://github.com/eventbrite/eventbrite-sdk-php/issues/7#issuecomment-308537756