1. 程式人生 > >golang,百度統計如何獲得pv,uv等資料

golang,百度統計如何獲得pv,uv等資料

百度統計的介面文件給的非常簡陋,這裡不貼了,找到這個部落格的人應該手裡已經捏了一份介面文件,但是接不通。
從介面文件上的要求來看,似乎僅僅需要傳:
【site_id,method,start_date,end_date,metrics,max_results,gran】
並且你以為傳遞的東西長這樣:

{
        "site_id":xxxxxx,
        "method":"source/all/a",
        "start_date":"20180826",
        "end_date":"20180826",
        "metrics":"pv_count,pv_ratio,visit_count,visitor_count,ip_count"
, "max_results":0, "gran":"day" }

但真正有效的,卻又沒有被寫進文件的樣例,是長這樣:

{
    "header":{
        "account_type":1,
        "username":"xxx",
        "password":"xxxxx",
        "token":"xxxxxxxxxxxxxxxxx"
    },
    "body":{
        "site_id":xxx,
        "method":"source/all/a",
        "methodxxxxxxxxx
":"visit/toppage/a", "start_date":"20180826", "end_date":"20180826", "metrics":"pv_count,pv_ratio,visit_count,visitor_count,ip_count", "max_results":0, "gran":"day" }
}

By the way,請求的method是POST,格式是 application/json
下面是講講多餘的沒寫進的資料是怎麼獲取到的:
account_type 是賬戶型別
username和password是你在百度統計登入的賬戶密碼
token在後臺的管理-匯出服務裡可以看到
詳情見這裡:

https://github.com/fwhezfwhez/baidutongji/blob/master/zhun-bei.md
也可以使用gitbook直接觀看書籍
git clone https://github.com/fwhezfwhez/baidutongji.git
然後使用gitbook-editor開啟。