You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
<?php
|
|
/**
|
|
* Demo of Tongji API
|
|
* set your information in Config.inc. php such as USERNAME, PASSWORD ... before use
|
|
* especially, you can modify this Demo on your need!
|
|
*/
|
|
$loginService = new \service\LoginService(BAIDU_LOGIN_URL, BAIDU_UUID);
|
|
|
|
// preLogin
|
|
if (!$loginService->preLogin(BAIDU_USERNAME, BAIDU_TOKEN)) {
|
|
exit();
|
|
}
|
|
|
|
// doLogin
|
|
$ret = $loginService->doLogin(BAIDU_USERNAME, BAIDU_PASSWORD, BAIDU_TOKEN);
|
|
if ($ret) {
|
|
$ucid = $ret['ucid'];
|
|
$st = $ret['st'];
|
|
}
|
|
else {
|
|
exit();
|
|
}
|
|
|
|
$reportService = new \service\ReportService(BAIDU_API_URL, BAIDU_USERNAME, BAIDU_TOKEN, $ucid, $st);
|
|
|
|
// get site list
|
|
$ret = $reportService->getSiteList();
|
|
|
|
$siteList = $ret['body']['data'][0]['list'];
|
|
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' => '20160501', //所查询数据的起始日期
|
|
'end_date' => '20160531', //所查询数据的结束日期
|
|
'metrics' => 'pv_count,visitor_count', //所查询指标为PV和UV
|
|
'max_results' => 0, //返回所有条数
|
|
'gran' => 'day', //按天粒度
|
|
));
|
|
}
|
|
|
|
// doLogout
|
|
$loginService->doLogout(BAIDU_USERNAME, BAIDU_TOKEN, $ucid, $st);
|
|
|