Hey,
Has anyone been able to access the API using PHP?
I can get an access token no problem and even refresh the token, but when I try to do anything else I just get a 401 error and the message "Authorization has been denied for this request".
Here's my function:
function globalMessage($token,$msg) {
$url = "http://localhost:5400/api/v1/chat/global";
$data = array
(
'Message' => $msg
);
$content = json_encode($data);
$headr=array();
$headr[]='Content-type: application/json';
$headr[]='Authorization: bearer '.$token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headr);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
return $response;
}
Anybody got any ideas?
I'm running this on my local machine, haven't tried from a web server yet.
It doesn't matter what I try to do with the API, I get the same error for everything. I used this to test by sending a global chat message as I thought it would be nice and simple!
Dave