PHP code example of qqjt / baidu-tongji

1. Go to this page and download the library: Download qqjt/baidu-tongji library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qqjt / baidu-tongji example snippets



Qqjt\BaiduTongji\Auth;
use Qqjt\BaiduTongji\Report;

$config = [
    /**
     * 1:站长账号
     * 2:凤巢账号
     * 3:联盟账号
     * 4:哥伦布账号
     */
    'account_type' => 1,
    'username' => 'aaa',
    'password' => 'bbb',
    'token' => 'ccc',
    'uuid' => 'ddd',
];

$auth = new Auth($config);

$res = $auth->login();

$config = array_merge($config, $res);

$report = new Report($config);

$siteRes = $report->getSiteList();
var_dump($siteRes);

$siteList = $siteRes['body']['data'][0]['list'];
$siteId = $siteList[0]['site_id'];
$parameters = [
    'site_id' => $siteId,                   //站点ID
    'method' => 'trend/time/a',             //趋势分析报告
    'start_date' => '20160501',             //所查询数据的起始日期
    'end_date' => '20160531',               //所查询数据的结束日期
    'metrics' => 'pv_count,visitor_count',  //所查询指标为PV和UV
    'max_results' => 0,                     //返回所有条数
    'gran' => 'day',                        //按天粒度
];
$dataRes = $report->getData($parameters);
var_dump($dataRes);

$auth->logout();