1

我正在尝试使用带有以下代码的Crocodoc api来获取状态。

$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;
    }
}

我没有得到状态,也没有错误。什么是错误的,或者它在评估模式下不起作用。现在我在 XAMPP 本地使用它,这可能是个问题吗?

4

1 回答 1

1

有什么doCurlGet作用?

因为请求(和响应)很好:

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"
  }
]

您可以尝试使用真正的卷曲,例如:

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

或直接:

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

编辑:

刚刚尝试了这段代码,它工作正常:

$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);
    }
}
于 2012-05-24T10:14:40.210 回答