问题
I tried to do it this way but it gives this error:
Fatal error: Class 'Piwik_FrontController' not found in C:\wamp\www\aqar2\piwik.php on line 11
my website path is :localhost/aqar2
my piwik path is: localhost/aqar2/piwik
<?php
// if you don't include 'index.php', you must also define PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"
define('PIWIK_INCLUDE_PATH', realpath('.localhost/aqar2/.'));
define('PIWIK_USER_PATH', realpath('.localhost/aqar2/.'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "piwik/index.php";
require_once PIWIK_INCLUDE_PATH . "piwik/core/API/Request.php";
Piwik_FrontController::getInstance()->init();
// This inits the API Request with the specified parameters
$request = new Piwik_API_Request('
method=UserSettings.getResolution
&idSite=1
&date=yesterday
&period=week
&format=XML
&filter_limit=3
&token_auth=&token_auth=a688c5c011dac27cf125eaa84f95e59b
');
// Calls the API and fetch XML data back
$result = $request->process();
echo $result;
?>
回答1:
If your php file is in localhost/aqar2/
then the path must be define('PIWIK_INCLUDE_PATH', realpath('piwik/'));
I know you probably fixed it already so i am adding that for whoever may need it...
回答2:
That error is a result of a class being used (or referenced) but not yet loaded. This is likely a result of your PIWIK_INCLUDE_PATH being incorrectly set, or that you are required to include the class yourself.
First, double check that the value set in your PIWIK_INCLUDE_PATH
is a valid path on the system, perhaps with:
if (is_dir(PIWIK_INCLUDE_PATH)) {
exit('IT IS A REAL PATH');
} else {
exit('IT IS NOT A REAL PATH');
}
If it turns out to not be a real path, perhaps you should look at the '.' dot prefix on your 'localhost' directory. Do you not mean to use realpath('localhost/aqar2/piwik');
. If that does work, you should also look at how you've set PIWIK_USER_PATH
.
If that does not work, you should look at including the FrontController class yourself, but this may mean that you have to manually include all of that classe's dependencies as well. To include the class manually, use include(PIWIK_INCLUDE_PATH . '/core/FrontController.php');
It would seem that directory structure you're trying to use is wrong, perhaps you should revise that and try to keep all files under the localhost
directory.
来源:https://stackoverflow.com/questions/9238534/how-to-set-up-a-direct-piwik-api-calling-in-php