百度统计 tongji API 的使用

通过百度统计获取网站的PV UV 各种数据 ;
首先你要有它的登录账号!

public function POST($data) {
    $this->genPostData($data);

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $this->url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //demo 里面这里的数是1  你要换成2 不然会报错 
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postData);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
里面有个地方有一个代码 LoginService.inc.php
 $retData = gzdecode($doLogin->retData, strlen($doLogin->retData));
换成
$retData = gzinflate(substr($doLogin->retData,10,-8));
if (count($siteList) > 0) {
    $siteId = $siteList[0]['site_id'];
    // get report data of the first site
    $ret = $reportService->getData(array(
        'site_id' => $siteId,                   //站点ID
        'method' => 'trend/time/a',             //趋势分析报告
        'start_date' => '20170328',             //所查询数据的起始日期
        'end_date' => '20170329',               //所查询数据的结束日期
        'metrics' => 'pv_count,visitor_count',  //所查询指标为PV和UV
        'max_results' => 0,                     //返回所有条数
        'gran' => 'day',                        //按天粒度
    ));
//    echo $ret['raw'] . PHP_EOL;
    $all_info = json_decode($ret['raw'],true);
  echo json_encode($all_info);

http://blog.163.com/zhuxun_why/blog/static/268139050201722961244335?ignoreua

你可能感兴趣的:(百度统计 tongji API 的使用)