首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Piwik API集成

Piwik API集成
EN

Stack Overflow用户
提问于 2015-05-29 13:53:23
回答 1查看 355关注 0票数 0

我试图编写一些php来从Piwik中提取数据。目前,我只想让它运行示例代码,但我做不到。我已经将它安装在一个名为analytics的目录中,我的代码是

代码语言:javascript
复制
            <?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行上的错误:文档是空的,下面是页面的呈现,直到第一个错误。

因此,它有点工作,但不完全。我找不到什么可以帮我的,所以如果你有什么想法,我会很感激的

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-01 08:16:51

你需要格式化你的代码。删除所有的回音你的代码,除了最后一个。如果将echo和XML混合使用,则XML输出将不正确。我不知道在您的真实文件中,您是否在每一行之前都有这些空白,但在这种情况下,也要删除它们。

因此,您的代码应该如下所示:

代码语言:javascript
复制
<?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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30531415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档