在Geckoboard php curl中获取无效的JSON错误

时间:2017-06-09 18:25:56

标签: php curl geckoboard

我正在尝试使用php curl在Geckoboard数据集中添加数据但是我得到了无效的json错误。请帮帮我。

请检查我的以下代码:

$ch = curl_init('https://api.geckoboard.com/datasets/sales.datasetidhere/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = array("articlePublished" => "6"); 
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_USERPWD, "Key:");

curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POSTFIELDS, 'data='.$data);

$response = curl_exec($ch);
$headers = curl_getinfo($ch);
print_r( $headers );
print_r( $response );

以下是回复:{“error”:{“message”:“服务器收到无效的JSON。”}}

0 个答案:

没有答案