Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle Error count(): Parameter must be an array or an object that implements Countable in

I am following with the article below, https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/web-php

But in the end, when I try with the sample code (HelloAnalytics.php), it will shows the error in command line as follows and cant get the data;

PHP Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67 PHP Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67 PHP Fatal error: Uncaught Google_Service_Exception: {"error":{"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Project 687417168367 is not found and cannot be used for API calls. If it is recently created, enable Google Analytics API by visiting https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","extendedHelp":"https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367"}],"code":403,"message":"Project 687417168367 is not found and cannot be used for API calls. If it is recently created, enable Google Analytics API by visiting https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}} in C:\xampp\htdocs\vendor\google\apiclient\s in C:\xampp\htdocs\vendor\google\apiclient\src\Google\Http\REST.php on line 118

Fatal error: Uncaught Google_Service_Exception: {"error":{"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Project 687417168367 is not found and cannot be used for API calls. If it is recently created, enable Google Analytics API by visiting https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","extendedHelp":"https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367"}],"code":403,"message":"Project 687417168367 is not found and cannot be used for API calls. If it is recently created, enable Google Analytics API by visiting https://console.developers.google.com/apis/api/analytics.googleapis.com/overview?project=687417168367 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}} in C:\xampp\htdocs\vendor\google\apiclient\s in C:\xampp\htdocs\vendor\google\apiclient\src\Google\Http\REST.php on line 118

Can somebody assist me? Thanks

like image 713
Dejiko Shima Avatar asked Dec 10 '22 06:12

Dejiko Shima


2 Answers

As stated here count(): Parameter must be an array or an object

Please try upgrading your version of Guzzle.

The problem is in PHP 7.2 the parameter for count() can't be NULL. The warning in the first post gets displayed when $this->handles equals NULL. Just replace line 67 in CurlFactory.php with the following:

if (($this->handles ? count($this->handles) : 0) >= $this->maxHandles) {

like image 67
DaImTo Avatar answered Dec 28 '22 08:12

DaImTo


Some people could meet this issue (in a local environment) when upgrading to Mac OS Catalina. This, upgraded my php version from 7.1 to 7.3, so I had the same issue with CurlFactory (used version 6.2.1 of Guzzle).

This can be fixed by updating your version of Guzzle to 6.3.0 (minimal). How to do this :

"require": {
    "guzzlehttp/guzzle": "^6.3.0"
}

Then in a terminal (in the root of your project) :

composer update

OR, if you can't change your Guzzle version (for a reason or another.. This is my case)

  • You can instead, change your version of php by installing 7.1 (with homebrew in my sample. If you don't have it you can find/install here : https://brew.sh/index)

Then in a terminal type :

brew update
brew install [email protected]

In some case, you'll have to link to php 7.1 with the following command :

brew link [email protected]

Finally, re-launch your terminal.

like image 41
KaN3d4 Avatar answered Dec 28 '22 07:12

KaN3d4