Google-api-php-client: count(): Parameter must be an array or an object

Created on 25 Jan 2018  ·  7Comments  ·  Source: googleapis/google-api-php-client

when i use this code

$service = new Google_Service_Urlshortener($client);              
$url = new Google_Service_Urlshortener_Url();
$url->setLongUrl($links);
$shortlink = $service->url->insert($url);

I got this warning

<p>Severity: Warning</p>
<p>Message:  count(): Parameter must be an array or an object that implements Countable</p>
<p>Filename: Handler/CurlFactory.php</p>
<p>Line Number: 67</p>

i think it only in php 7.2 was fine in 7.1

p2 bug

Most helpful comment

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) {

All 7 comments

Stack trace for the same issue:

GuzzleHttp\Handler\CurlFactory::release() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php, line 67
--
  | GuzzleHttp\Handler\CurlFactory::finish() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php, line 107
  | GuzzleHttp\Handler\CurlHandler::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php, line 43
  | GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php, line 28
  | GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php, line 51
  | GuzzleHttp\PrepareBodyMiddleware::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php, line 72
  | GuzzleHttp\Middleware::GuzzleHttp\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Middleware.php, line 30
  | GuzzleHttp\RedirectMiddleware::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php, line 68
  | GuzzleHttp\Middleware::GuzzleHttp\{closure}() - ROOT/vendor/guzzlehttp/guzzle/src/Middleware.php, line 57
  | GuzzleHttp\HandlerStack::__invoke() - ROOT/vendor/guzzlehttp/guzzle/src/HandlerStack.php, line 67
  | GuzzleHttp\Client::transfer() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 275
  | GuzzleHttp\Client::sendAsync() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 97
  | GuzzleHttp\Client::send() - ROOT/vendor/guzzlehttp/guzzle/src/Client.php, line 104
  | Google\Auth\HttpHandler\Guzzle6HttpHandler::__invoke() - ROOT/vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php, line 34
  | Google\Auth\OAuth2::fetchAuthToken() - ROOT/vendor/google/auth/src/OAuth2.php, line 501
  | Google_Client::fetchAccessTokenWithAuthCode() - ROOT/vendor/google/apiclient/src/Google/Client.php, line 191

It seems that this issue has been already been solved in guzzle https://github.com/guzzle/guzzle/pull/1686, however google api links to a specific version of guzzle which is older than the fix.

try

   $shortlink = $service->url->insert("https://example.com");

If that doesnt work try

   $optParams = array('fields' => '*');
   $shortlink = $service->url->insert("https://example.com",  $optParams);

Same type of error when using:

$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);

"count(): Parameter must be an array or an object that implements Countable"

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) {

Please try upgrading your version of Guzzle.

Links to Can't quickstart with PHP for Google Analytics Note this is not my question i am just linking it here for documentation reasons.

Please try upgrading your version of Guzzle.

s pozdravem,

Filip Oščádal

On Mon, Jun 18, 2018 at 8:25 AM Linda Lawton notifications@github.com
wrote:

Links to Can't quickstart with PHP for Google Analytics
https://stackoverflow.com/q/50898330/1841839


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/google-api-php-client/issues/1377#issuecomment-397953716,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEmXukQxg_rRnAxoTq4eZVZinRpCavNks5t90fggaJpZM4RsLDh
.

Was this page helpful?
0 / 5 - 0 ratings