使用百度分析的 API

文档

Tongji API用户手册

开通token

[管理] [数据导出服务]

使用百度分析的 API

(不是商业账号 没有token的

账号类型

必须是百度商业账号,
tongji.baidu.com/web/welcome/login...
花费几分钟申请下吧。

把pv刷到100 第二天起来再开通

使用百度分析api

别熬夜等待,没用,大概到9点才会刷新数据导出服务统计。

请求格式 (注意: 都是放到body的)

使用百度分析api

封装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

吐槽

自己实现统计

太麻烦了,又怕出问题

百度统计api的请求

我很懵逼。

  1. 发送请求需要账号 密码
  2. 请求参数都是放到body,我之前还以为是放到 header
本作品采用《CC 协议》,转载必须注明作者和本文链接
专心学习不瞎搞
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
89
粉丝
108
喜欢
481
收藏
724
排名:108
访问:8.8 万
私信
所有博文
社区赞助商