piwik api: 调用api数据

2024-03-25 13:08
文章标签 数据 调用 api piwik

本文主要是介绍piwik api: 调用api数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.关于api



2.api的使用

参考网址:http://developer.piwik.org/guides/querying-the-reporting-api

<?php
use Piwik\API\Request;
use Piwik\FrontController;define('PIWIK_INCLUDE_PATH', realpath('../..'));
define('PIWIK_USER_PATH', realpath('../..'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
require_once PIWIK_INCLUDE_PATH . "/index.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";FrontController::getInstance()->init();// This inits the API Request with the specified parameters
$request = new Request('module=API&method=UserSettings.getResolution&idSite=7&date=yesterday&period=week&format=XML&filter_limit=3&token_auth=anonymous
');
// Calls the API and fetch XML data back
$result = $request->process();
echo $result;Here is the output of this script:<?xml version="1.0" encoding="utf-8" ?>
<result><row><label>1920x1080</label><nb_visits>1742</nb_visits><nb_actions>4343</nb_actions><max_actions>89</max_actions><sum_visit_length>349083</sum_visit_length><bounce_count>1135</bounce_count><nb_visits_converted>52</nb_visits_converted><sum_daily_nb_uniq_visitors>1503</sum_daily_nb_uniq_visitors></row><row><label>1366x768</label><nb_visits>1045</nb_visits><nb_actions>2214</nb_actions><max_actions>38</max_actions><sum_visit_length>147636</sum_visit_length><bounce_count>747</bounce_count><nb_visits_converted>26</nb_visits_converted><sum_daily_nb_uniq_visitors>937</sum_daily_nb_uniq_visitors></row><row><label>1680x1050</label><nb_visits>533</nb_visits><nb_actions>1358</nb_actions><max_actions>47</max_actions><sum_visit_length>117723</sum_visit_length><bounce_count>345</bounce_count><nb_visits_converted>11</nb_visits_converted><sum_daily_nb_uniq_visitors>459</sum_daily_nb_uniq_visitors></row>
</result>

api调用的方式:

<?php
exit; // REMOVE this line to run the script// this token is used to authenticate your API request.
// You can get the token on the API page inside your Piwik interface
$token_auth = 'anonymous';// we call the REST API and request the 100 first keywords for the last month for the idsite=7
$url = "http://demo.piwik.org/";
$url .= "?module=API&method=Referrers.getKeywords";
$url .= "&idSite=7&period=month&date=yesterday";
$url .= "&format=PHP&filter_limit=20";
$url .= "&token_auth=$token_auth";$fetched = file_get_contents($url);
$content = unserialize($fetched);// case error
if (!$content) {print("Error, content fetched = " . $fetched);
}print("<h1>Keywords for the last month</h1>");
foreach ($content as $row) {$keyword = htmlspecialchars(html_entity_decode(urldecode($row['label']), ENT_QUOTES), ENT_QUOTES);$hits = $row['nb_visits'];print("<b>$keyword</b> ($hits hits)<br>");
}Here is the output of this code:<h1>Keywords for the last month</h1><b>Keyword not defined</b> (16481 hits)<br><b>xxxxxx</b> (80 hits)<br><b>xxx.xxx</b> (9 hits)<br><b>downloads anzeigen</b> (7 hits)<br><b>youtube-downloader.savetubevideo.com / referral</b> (4 hits)<br><b>meine downloads anzeigen</b> (3 hits)<br><b>understanding piwik</b> (3 hits)<br><b>bbw highway .com</b> (2 hits)<br><b>imgsrc</b> (2 hits)<br><b>piwik</b> (2 hits)<br><b>piwik deutsch</b> (2 hits)<br><b>piwik exporting reports</b> (2 hits)<br><b>piwik failed to load html file</b> (2 hits)<br><b>piwik not tracking</b> (2 hits)<br><b>piwik sharepoint</b> (2 hits)<br><b>premature end of data</b> (2 hits)<br><b>vertrag mit piwik zur auftragsdatenverarbeitung</b> (2 hits)<br><b>wp-piwik einrichten</b> (2 hits)<br><b>"edt 2014 x86_64" ext:php</b> (1 hits)<br><b>"failed to load html file" piwik plugins/sitesmanager/templates/index.html</b> (1 hits)<br


这篇关于piwik api: 调用api数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845102

相关文章

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

MyBatisPlus如何优化千万级数据的CRUD

《MyBatisPlus如何优化千万级数据的CRUD》最近负责的一个项目,数据库表量级破千万,每次执行CRUD都像走钢丝,稍有不慎就引起数据库报警,本文就结合这个项目的实战经验,聊聊MyBatisPl... 目录背景一、MyBATis Plus 简介二、千万级数据的挑战三、优化 CRUD 的关键策略1. 查

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

mysql中的数据目录用法及说明

《mysql中的数据目录用法及说明》:本文主要介绍mysql中的数据目录用法及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、版本3、数据目录4、总结1、背景安装mysql之后,在安装目录下会有一个data目录,我们创建的数据库、创建的表、插入的

Python中Tensorflow无法调用GPU问题的解决方法

《Python中Tensorflow无法调用GPU问题的解决方法》文章详解如何解决TensorFlow在Windows无法识别GPU的问题,需降级至2.10版本,安装匹配CUDA11.2和cuDNN... 当用以下代码查看GPU数量时,gpuspython返回的是一个空列表,说明tensorflow没有找到

Navicat数据表的数据添加,删除及使用sql完成数据的添加过程

《Navicat数据表的数据添加,删除及使用sql完成数据的添加过程》:本文主要介绍Navicat数据表的数据添加,删除及使用sql完成数据的添加过程,具有很好的参考价值,希望对大家有所帮助,如有... 目录Navicat数据表数据添加,删除及使用sql完成数据添加选中操作的表则出现如下界面,查看左下角从左

SpringBoot中4种数据水平分片策略

《SpringBoot中4种数据水平分片策略》数据水平分片作为一种水平扩展策略,通过将数据分散到多个物理节点上,有效解决了存储容量和性能瓶颈问题,下面小编就来和大家分享4种数据分片策略吧... 目录一、前言二、哈希分片2.1 原理2.2 SpringBoot实现2.3 优缺点分析2.4 适用场景三、范围分片

python如何调用java的jar包

《python如何调用java的jar包》这篇文章主要为大家详细介绍了python如何调用java的jar包,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以参考一下... 目录一、安装包二、使用步骤三、代码演示四、自己写一个jar包五、打包步骤六、方法补充一、安装包pip3 install

Redis分片集群、数据读写规则问题小结

《Redis分片集群、数据读写规则问题小结》本文介绍了Redis分片集群的原理,通过数据分片和哈希槽机制解决单机内存限制与写瓶颈问题,实现分布式存储和高并发处理,但存在通信开销大、维护复杂及对事务支持... 目录一、分片集群解android决的问题二、分片集群图解 分片集群特征如何解决的上述问题?(与哨兵模

浅析如何保证MySQL与Redis数据一致性

《浅析如何保证MySQL与Redis数据一致性》在互联网应用中,MySQL作为持久化存储引擎,Redis作为高性能缓存层,两者的组合能有效提升系统性能,下面我们来看看如何保证两者的数据一致性吧... 目录一、数据不一致性的根源1.1 典型不一致场景1.2 关键矛盾点二、一致性保障策略2.1 基础策略:更新数