Can't get API to work

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:


// Version: 1.1; Statistik

function template_main()


    echo '
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <td valign="top">
        <br />
Hier möchten wir Dir zukünftig Statistiken des 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
// we call the REST API and request the 100 first keywords for the last month for the idsite=1
$url = "";
$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
    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 '



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?

i think you’re missing something like “/piwik/index.php” after your “”…

Hm, no, same problem with:

$url = "";


Make sure allow_url_fopen=1

Print out the url and make sure it works from the browser