简体   繁体   中英

Crocodoc api not working with php

I am trying to use Crocodoc api with the following code to get the status.

$croco = new Crocodoc();

$uuids = "786e072b-981c-4d2a-8e80-80e215f1f7c2";
echo "\n\nchecking status of : ", $uuids;
$status = $croco->getStatus($uuids);
echo "\n\nstatus is : ", $status;

class Crocodoc { 
    public $api_key = 'HPUd6LZXg5174TAENbvBcx30';
    public $api_url = 'https://crocodoc.com/api/v2/';

    public function getStatus($uuids){
        $url = $this->api_url.'document/status';
        $token = $this->api_key;
        $dataStr = '?token='.$token.'&uuids='.$uuids;
        // this is a GET request
        $output = $this->doCurlGet($url, $dataStr);
        return $output;
    }
}

I don't get the status and no error. What is wrong or it does not work in evaluation mode. Right now I am using it local with XAMPP, can that be a problem?

What doCurlGet does?

Because the request (and response) is fine:

HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Thu, 24 May 2012 10:11:27 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive

[
  {
    "uuid": "786e072b-981c-4d2a-8e80-80e215f1f7c2",
    "viewable": true,
    "status": "DONE"
  }
]

You might try with a real curl, like:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "/* generated url to crocodoc */");
$data = curl_exec($ch);
curl_close($ch);

Or directly:

$data = file_get_contents('/* generated url to crocodoc */');

Edit:

Just tried this code , and it works fine:

$croco  = new Crocodoc();
$uuids  = "786e072b-981c-4d2a-8e80-80e215f1f7c2";
$status = $croco->getStatus($uuids);
var_dump($status);

class Crocodoc { 
    public $api_key = 'HPUd6LZXg5174TAENbvBcx30';
    public $api_url = 'https://crocodoc.com/api/v2/';

    public function getStatus($uuids){
        $url = $this->api_url.'document/status';
        $token = $this->api_key;
        $dataStr = '?token='.$token.'&uuids='.$uuids;

        // this is a GET request
        return file_get_contents($url.$dataStr);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM