Skip to content
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

Closed
AntoineWtrnd opened this issue Mar 24, 2019 · 9 comments · Fixed by #14263
Labels
c: Website matomo.org For issues related to our matomo.org website. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Comments

@AntoineWtrnd
Copy link

AntoineWtrnd commented Mar 24, 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
Copy link
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
Copy link
Author

AntoineWtrnd commented Mar 24, 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
Copy link
Author

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
Copy link
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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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 Findus23 added the c: Website matomo.org For issues related to our matomo.org website. label Mar 24, 2019
@Findus23
Copy link
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
Copy link
Author

You're the man.

Thanks alot bro.

@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Jun 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Website matomo.org For issues related to our matomo.org website. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants