Harvest API php没有输出

时间:2014-05-09 19:52:26

标签: php curl harvest

我正在尝试从GitHub页面处理Harvest php API示例。

这是代码,但无论我尝试做什么都没有输出。如果我使用Chrome Postman应用程序,我可以检索数据。我不确定我做错了什么。机密信息已删除。任何帮助深表感谢。

<?php

$url = "https://company.harvestapp.com/?daily=";

$temp = getURL($url);
echo $temp;

function getURL($url) { 

    $credentials = "<email>:<password>";
    $headers = array(
        "Content-Type: application/xml",
        "Accept: application/xml",
        "Authorization-Basic: " . base64_encode($credentials)
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_USERAGENT, "test app site");

    $data = curl_exec($ch);
    curl_close($ch);

    if ($data !=false){
        return $data;
        }
    else
        return "no data";

}
?>

这是我从curl_error函数得到的错误:

  

HTTP / 1.1 401 Unauthorized Server:nginx日期:星期五,09五月2014 22:59:27 GMT内容类型:application / xml; charset = utf-8传输编码:chunked连接:keep-alive状态:401未授权的缓存控制:私有,无存储,无缓存,max-age = 0,必须重新验证X-Frame选项:SAMEORIGIN X -Served-From:https://.harvestapp.com/ X-UA-Compatible:IE = Edge,chrome = 1 Set-Cookie:_harvest_sess =;域= .harvestapp.com;路径= /;安全; HttpOnly X-Request-Id:e9d6eb74-5c73-430e-9854-ebf6f1c527c8 X-Runtime:0.019223您必须通过Harvest进行身份验证才能完成此请求。

0 个答案:

没有答案