I am working on an Ubuntu server attempting to use the PHP wrapper for the Challonge API. I am only able to get 404 error codes back. I have been debugging the wrapper to see where everything goes wrong. Following are some of my observations.
My main PHP looks like this
include('challonge.class.php');
$c = new ChallongeAPI(API_Key); //I have tried this with just my key, as well as in '' and ""
$t = $c->getTournaments();
echo $c->status_code; //This should echo out 200 if it all works correctly
The above code was yielding nothing, so I delved into challonge.class.php (the wrapper) to see if I could find what was going wrong. I discovered that status_code would be 404 before a switch statement would print errors, but I never saw any errors. Here is the segment of code where I have decided the problem is
$curl_result = curl_exec($curl_handle);
$info = curl_getinfo($curl_handle);
$this->status_code = (int) $info['http_code']; //status_code is 404 here
$return = false;
if ($curl_result === false) {
// CURL Failed
$this->errors[] = curl_error($curl_handle);
} else {
switch ($this->status_code) {
case 401: // Bad API Key
case 422: // Validation errors
case 404: // Not found/Not in scope of account
//Everything is good here
$return = $this->result = new SimpleXMLElement($curl_result);
//Everything went wrong; cannot echo anything
foreach($return->error as $error) {
$this->errors[] = $error;
}
$return = false;
break;
...
To me, this means that new SimpleXMLElement($curl_result);
is causing the problem. I do not however know how to find out why. To my knowledge, SimpleXML is installed just fine regardless of why I am getting a 404. I am at a loss for what is going on here or what mistakes I am making.
I have solved this problem myself. The reason creating a SimpleXMLElement would throw an error is because Challonge was giving me a 404 error page instead of an xml response. This is due to the PHP wrapper for the Challonge API being outdated.
The plugin uses this URL format for sending requests
$call_url = "https://challonge.com/api/v1/".$path.'.xml';
The API describes the correct URL format for making HTTP requests as
$call_url = "https://api.challonge.com/v1/".$path.'.xml';
Making this simple change in the wrapper class solves the problem
I have solved this problem myself. The reason creating a SimpleXMLElement would throw an error is because Challonge was giving me a 404 error page instead of an xml response. This is due to the PHP wrapper for the Challonge API being outdated.
The plugin uses this URL format for sending requests
$call_url = "https://challonge.com/api/v1/".$path.'.xml';
The API describes the correct URL format for making HTTP requests as
$call_url = "https://api.challonge.com/v1/".$path.'.xml';
Making this simple change in the wrapper class solves the problem