@AntoineWtrnd opened this Issue on March 24th 2019

Hello,

Again and again and again, another bug in Matomo.
Trying to call API, using the exactly same code that you provide (https://developer.matomo.org/guides/querying-the-reporting-api)

``Here is the error:
Warning: Illegal string offset 'label' in /home/xxxxx on line 82

Warning: Illegal string offset 'nb_visits' in /home/xxxxx
e (e hits)

Warning: Illegal string offset 'label' in /home/xxxxx on line 82

Warning: Illegal string offset 'nb_visits' in /home/xxxxx on line 83
A (A hits)``

BUT YOUR DOCUMENTATION INDICATE THAT THIS IS THE REAL OUTPUT
This can't be real that you provide us PHP script to throw error ? Dudeeeeeee ?

Just installed it, should probably passed all bug exist in this software. Really unstable. I really don't get it how big company can use this.

@Findus23 commented on March 24th 2019 Member

Hi,
it would help with troubleshooting if you could provide more details.
In which file does the error occur? What API request are you doing exactly?

@AntoineWtrnd commented on March 24th 2019

Hello,

As i writed, i used exactly the same script as Matomo provide us.
But just realized that it is supposed to be the right ouput, but i can't be real ?

Here the script i've used:

<?php
exit; // REMOVE this line to run the script

// this token is used to authenticate your API request.
// You can get the token on the API page inside your Matomo interface
$token_auth = 'my api token';

// we call the REST API and request the 100 first keywords for the last month for the idsite=7
$url = "my url";
$url .= "?module=API&method=Referrers.getKeywords";
$url .= "&idSite=7&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>\n");
foreach ($content as $row) {
    $keyword = htmlspecialchars(html_entity_decode(urldecode($row['label']), ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
    $hits = $row['nb_visits'];

    print("<b>$keyword</b> ($hits hits)<br>\n");
}
@AntoineWtrnd commented on March 24th 2019

Take a look on that: https://developer.matomo.org/guides/querying-the-reporting-api

This is crazy that Matomo developer provide us with error ? I just can't believe that. It should be a mistake.

@Findus23 commented on March 24th 2019 Member

Hi,

The PHP error doesn't happen in Matomo, but in the script that makes the HTTP request to the Matomo API.

It seems like the API doesn't return any keywords and therefore you can't loop over them.
Check if there are keywords in your Matomo instance.

@AntoineWtrnd commented on March 24th 2019

Hello, thanks for your help, really appreciated.

But did you notice on the URL i provide you that Matomo team say that this error should be the output.

And yes i have keywords, also, tried with the previous install i had, gived me the same error. That why i reainstall it.

@AntoineWtrnd commented on March 24th 2019

And yes, the error is a part of Matomo source, even if i call the API outside the URL (but same IP), so problem is from Matomo. I run dedicated server, i can confirm you that i enabled all function to make it work.

@AntoineWtrnd commented on March 24th 2019

Take a look on internet which cause this problem, look like this come from an empty string. But yes i have keywords and atleast, it should probably return something like "No data" instead of throwing error like this lol.

@Findus23 commented on March 24th 2019 Member

You are right that this example is a bit outdated.

I'd recommend you to simply use API as described in https://developer.matomo.org/api-reference/reporting-api to fetch JSON data and then handle this in your script.

@AntoineWtrnd commented on March 24th 2019

You're the man.

Thanks alot bro.

This Issue was closed on March 28th 2019
Powered by GitHub Issue Mirror