Jump to content

DaveCain

Members
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

692 profile views
  1. Well, after spending so much time on this, it was something as simple as needing to update my version... Also the original code does now work. Thanks for everyone's input!
  2. Yeah I'm on 0.6.0.0 according to the server, but I only downloaded it about 3 weeks ago or so. I'll see if I can upgrade it!
  3. I can see it worked for you, but I literally copied this code and I got a 401 error still. As I could see no errors in my code, I'm starting to wonder if it's something to do with the "PHP Desktop" I'm using. It's normally fine but for some reason it just doesn't seem to allow this to work. I'll try again with some other kind of WAMP server. Edit: Still the same. I literally copied you code exactly, I still get the token ok, but I get a 401 when calling the globalMessage function. It's really annoying me now, I know the code is correct but it just won't work.
  4. 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
Γ—
Γ—
  • Create New...