[英]Submitting a POST request to Piwik.php
我正在嘗試向Piwik跟蹤api(/piwik.php)發送批量請求,我遇到了問題。 當我發送請求時(從PHP腳本通過ajax,curl和fiddler2),我收到以下內容:
Debug enabled - Input parameters:<br/>array ( )
token_auth is authenticated!
Loading plugins: { Provider,Goals,UserCountry }
Current datetime: 2013-05-02 16:02:27
The request is invalid: empty request, or maybe tracking is disabled in the config.ini.php via record_statistics=0
我的帖子看起來像這樣:
{"requests":["%3Fidsite%3D1%26url%3Dhttp%3A%2F%2Fexample.org%26action_name%3DTest+bulk+log+Pageview%26rec%3D1"],"token_auth":"mytokenhere"}
這是他們網站上的例子。 我已確保將content-type設置為“Content-Type:application / json”,並且我的配置已明確定義record_statistics = 1。
根據文檔,這應該都可以,但我仍然得到空的請求。 import_logs.py腳本也有效,所以我知道一般批量導入沒有被破壞,但我不知道如何讓程序接受我的數據。 有人有運氣嗎?
謝謝!
您的請求的問題可能是您的查詢字符串是URL編碼的,但它們不需要是因為它們是POST主體的一部分。
你的POST應該是這樣的:
{"requests":["?idsite=1&url=http://example.org&action_name=Test+bulk+log+Pageview&rec=1"],"token_auth":"mytokenhere"}
請參閱批量跟蹤API文檔中的示例: http : //piwik.org/docs/tracking-api/reference/#toc-advanced-bulk-tracking-requests
弄清楚出了什么問題。 他們的文檔在如何格式化請求時是不正確的。 首先,URL編碼數據是不必要的。 其次,JSON字符串需要如下所示:
{
"requests": [
{
"apiv": "1",
"bots": "1",
"idsite": "1",
"download": "",
"cdt": "",
"dp": "",
"url": "",
"urlref": "",
"cip": "",
"ua": "",
"_cvar": {
"1": [
"Not-Bot",
"Mozilla/5.0+(Macintosh;+U;+Intel+Mac+OS+X+10_6_5;+en-US)+AppleWebKit/534.10+(KHTML,+like+Gecko)+Chrome/8.0.552.231+Safari/534.10"
]
},
"rec": "1"
}
]
}
並非所有這些數據都需要發送,但這是必要的格式。 之后,它只是數據清理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.