使用百度分析的 API
文档
开通token
[管理] [数据导出服务]
(不是商业账号 没有token的)
账号类型
必须是百度商业账号,
tongji.baidu.com/web/welcome/login...
花费几分钟申请下吧。
把pv刷到100 第二天起来再开通
别熬夜等待,没用,大概到9点才会刷新数据导出服务统计。
请求格式 (注意: 都是放到body的)
封装body代码
(详细发起请求的代码不发了,框架不一致)
<?php
namespace App\Service;
/**
** 功能详细见: https://tongji.baidu.com/api/manual/Chapter1/getData.html
*/
trait BaiduAnalysisGetData
{
protected $options = [];
public function setSiteId($site_id)
{
$this->options['site_id'] = $site_id;
return $this;
}
public function setMethod($method)
{
$this->options['method'] = $method;
return $this;
}
public function setGran($gran)
{
$this->options['gran'] = $gran;
return $this;
}
public function setStartDate($start_date)
{
$this->options['start_date'] = $start_date;
return $this;
}
public function setEndDate($end_date)
{
$this->options['end_date'] = $end_date;
return $this;
}
public function setStartDate2($start_date2)
{
$this->options['start_date2'] = $start_date2;
return $this;
}
public function setEndDate2($end_date2)
{
$this->options['end_date2'] = $end_date2;
return $this;
}
public function setMetrics(string $metrics)
{
$this->options['metrics'] = $metrics;
return $this;
}
public function setOrder($order)
{
$this->options['order'] = $order;
return $this;
}
public function setStartIndex($start_index)
{
$this->options['start_index'] = $start_index;
return $this;
}
public function setmaxResults($max_results)
{
$this->options['max_results'] = $max_results;
return $this;
}
}
最后使用
吐槽
自己实现统计
太麻烦了,又怕出问题
百度统计api的请求
我很懵逼。
- 发送请求需要
账号
密码
- 请求参数都是放到
body
,我之前还以为是放到header
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: