The API, in this situation, should be called from the method get
.
If you do visit the API at this link: https://api.stackexchange.com/2.1/comments?order=desc&sort=creation&site=stackoverflow
You are presented with a nice JSON with all the information you want.
If instead, you fix up the post params:
$params = array('http' => array(
'method' => 'POST',
'content' => $data,
'header' => 'Content-Length: ' . strlen($data)
));
You are shown this instead:
{"error_id":404,"error_name":"no_method","error_message":"this method cannot be called this way"}
Hopefully you know that you can simply just use file_get_contents
to contact the API with the traditional get.
$json = json_decode(file_get_contents("https://api.stackexchange.com/2.1/comments?order=desc&sort=creation&site=stackoverflow"), true);