[TYPO3-piwik] Get Piwik data from own PHP

Peter Kindström typo3 at campingwebben.se
Mon Feb 8 20:19:10 CET 2010


Hi list,
Now I want to get data from Piwik from my own PHP script. But I don't
get it to work...

I put my PHP code on the same server as Typo3 with the piwikintegration
extension, in Piwik admin interface I set both the Costumer 0 and 1
website user 'anonymous' to have View rights, I have generate a API
code/key and put the following code in my PHP file:

<?php
define('PIWIK_PATH', 'http://[mydomain]/typo3conf/piwik/piwik/');
define('PIWIK_TOKEN', '12345678901234567890');

$url = PIWIK_PATH; 
$url .= "?module=API";
$url .= "&method=VisitsSummary.getVisits";
$url .= "&idSite=0";
$url .= "&period=week";
$url .= "&date=last5";
$url .= "&format=PHP";
$url .= "&filter_limit=20";
$url .= "&token_auth=".PIWIK_TOKEN;
$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><p>");
foreach($content as $row) {
$keyword = urldecode($row['label']);
$hits = $row['nb_visits'];
print("<b>$keyword</b> ($hits hits)<br>");
}
print("</p>");
?>

When I comment out the 'unserialize' row I get an error message saying:
"Error, content fetched =
a:2:{s:6:"result";s:5:"error";s:7:"message";s:85:"You can't access this
resource as it requires a 'view' access for the website id = 0.";}"

Any idea of what I am doing wrong?


Kind regards,
Peter Kindström, Campingwebben



More information about the TYPO3-project-piwik mailing list