@LeCoyote opened this Issue on July 28th 2015

Ref: #3921

It seems that calling the API in PHP is still partly broken.

Using the code provided in http://developer.piwik.org/guides/querying-the-reporting-api results in a piece of code that changes the default timezone to UTC. In other words, using Piwik as documented will force the calling code to use UTC as a default timezone. This behaviour is intrusive and not documented. I'll see if I can edit the wiki later.

Moreover, the code sample mentions:
// 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"
Clearly, this is not sufficient. Doing so will result in the following:
PHP Fatal error: Class 'Piwik\\Application\\Environment' not found in <path>
This part of the documentation cannot be edited via the wiki.

As a result, there still seems to be no clean way of using the API directly in PHP.

@LeCoyote commented on July 28th 2015

Apparently, the "correct" way to include the API would be:

require_once PIWIK_INCLUDE_PATH . "/libs/upgradephp/upgrade.php";
require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php";

// Additional includes missing from documentation
require_once PIWIK_INCLUDE_PATH . '/vendor/autoload.php';

This is for 2.14.2 ; 2.14.1 still appears to have the old core/Loader.php (which for some reason does not get deleted when upgrading from 1.x, but that's another issue and frankly, I'm too annoyed to create another one for now)

@mattab commented on September 18th 2015 Owner

Thanks for feedback @LeCoyote. I removed the outdated comment in https://github.com/piwik/piwik/commit/6d86b4de423e01cda87b9a73fa5934d8ce75a4f8.

When I try the code in developer doc, it works for me. if you still have a problem please create a new issue and put your whole test code we can use to reproduce the issue

This Issue was closed on September 18th 2015
Powered by GitHub Issue Mirror