Hi there,
I’m trying to get API to work. I want to use it to show the members of our SMF forum some statistics about our forum. Therefor we build a PHP template file with this code inside:
<?php
// Version: 1.1; Statistik
function template_main()
{
echo '
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<br />
<p><b>Statistiken</b></p>
Hier möchten wir Dir zukünftig Statistiken des SMFPortal.de präsentieren. Bitte habe noch ein wenig Geduld. Während der Testphase kann es zeitweise zu unvollständigen oder fehlerhaften Darstellungen der Statistiken kommen. Wir bitten dies zu entschuldigen.<br /><br />';
// this token is used to authenticate your API request.
// You can get the token on the API page inside your Piwik interface
$token_auth='12345';
// we call the REST API and request the 100 first keywords for the last month for the idsite=1
$url = "http://www.smfportal.de/";
$url .= "?module=API&method=Referers.getKeywords";
$url .= "&idSite=1&period=month&date=yesterday";
$url .= "&format=PHP&filter_limit=20";
$url .= "&token_auth=$token_auth";
$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>");
foreach($content as $row)
{
$keyword = urldecode($row['label']);
$hits = $row['nb_visits'];
print("<b>$keyword</b> ($hits hits)<br>");
}
echo '
</td>
</tr>
</table>';
}
?>
The Piwik folder lays inside the forum folder and is called pwk. When we open the site, we get the following:
Error, content fetched =
Oh, I changed the token_auth in the code above. In the original file I use the correct one.
Any suggestions what I’ve done wrong?