我试图编写一些php来从Piwik中提取数据。目前,我只想让它运行示例代码,但我做不到。我已经将它安装在一个名为analytics的目录中,我的代码是
<?php
use Piwik\API\Request;
use Piwik\FrontController;
echo "result script loaded";
define('PIWIK_INCLUDE_PATH', realpath('../../')."/httpdocs/analytics/");
define('PIWIK_USER_PATH', realpath('../../'."/httpdocs/analytics/"));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
echo "<br/>1 PIWIK_INCLUDE_PATH: ".PIWIK_INCLUDE_PATH;
// 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=Resolution.getResolution
&idSite=all
&date=last4
&period=month
&format=XML
&filter_limit=3
&token_auth=anonymous
');
// Calls the API and fetch XML data back
echo "<br/>here";
$result = $request->process();
echo $result;
?>这会运行但会产生
此页包含以下错误:
第1列第1行上的错误:文档是空的,下面是页面的呈现,直到第一个错误。
因此,它有点工作,但不完全。我找不到什么可以帮我的,所以如果你有什么想法,我会很感激的
谢谢
发布于 2015-06-01 08:16:51
你需要格式化你的代码。删除所有的回音你的代码,除了最后一个。如果将echo和XML混合使用,则XML输出将不正确。我不知道在您的真实文件中,您是否在每一行之前都有这些空白,但在这种情况下,也要删除它们。
因此,您的代码应该如下所示:
<?php
use Piwik\API\Request;
use Piwik\FrontController;
define('PIWIK_INCLUDE_PATH', realpath('../../')."/httpdocs/analytics/");
define('PIWIK_USER_PATH', realpath('../../'."/httpdocs/analytics/"));
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=Resolution.getResolution
&idSite=all
&date=last4
&period=month
&format=XML
&filter_limit=3
&token_auth=anonymous
');
// Calls the API and fetch XML data back
$result = $request->process();
echo $result;https://stackoverflow.com/questions/30531415
复制相似问题