New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fresh new install, trying to call API with your OWN example: Warning: Illegal string offset 'nb_visits' #14262
Comments
Hi, |
Hello, As i writed, i used exactly the same script as Matomo provide us. 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");
} |
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. |
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. |
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. |
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. |
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. |
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. |
You're the man. Thanks alot bro. |
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.
The text was updated successfully, but these errors were encountered: