Php-graph-sdk: Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given

Created on 9 Mar 2017  路  10Comments  路  Source: facebookarchive/php-graph-sdk

Hi,

I just booted up a new puphpet virtual machine and tried to run this basic example: https://github.com/facebook/php-graph-sdk/blob/5.4/docs/examples/facebook_login.md

I got this following error on the callback page:

( ! ) Catchable fatal error: Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given, called in /var/www/backend/www/vendor/guzzlehttp/guzzle/src/Client.php on line 87 and defined in /var/www/backend/www/vendor/guzzlehttp/guzzle/src/Client.php on line 126

See the Stacktrace:
screen shot 2017-03-09 at 14 40 01

This is the puphpet configuration, in case you wanted to try it out by yourself. https://gist.github.com/klausbreyer/2e422f660c41a3d393b7f98e43b46c7a

Most helpful comment

Just ran into the same issue.

The problem is that graph-sdk only requires Guzzle 5 in require-dev, so you can install Guzzle 6 through a regular require in your main project.

Graph SDK then detects the presence of the GuzzleHttp\Client class, assumes it is Guzzle 5 and goes on to use it incorrectly, triggering the fatal error mentioned above.

For me, the quick fix was to just tell Graph SDK to not use Guzzle but instead curl or stream. You can do this by passing an option when creating your Facebook\Facebook object:

$facebook = new Facebook\Facebook(['http_client_handler' => 'stream']);

All 10 comments

This is my composer.lock with the exact versions: https://gist.github.com/klausbreyer/b3b371ed9ff646032948acfba8e591c9

I too am receiving this issue whilst trying to issue a

$fb->get('/me', '{token}');

from what i can tell from looking through the source is that at line 61 in FacebookGuzzleHttpClient it attempts to use a function called createRequest, which doesn't exist on the version of guzzle i have (Guzzle 6.2.1).

That then invokes the magic call on the guzzle client (line 76 GuzzleHttp\Client), passing 'createRequest' as the method name and the url as the second argument. The magic call on guzzle expects the second parameter to be an array and tests count() < 1 on it.

Of course php being php considers a string to have a count of one so this check succeeds, and then the string url is passed to the request() method as the options array (line 87 GuzzleHttp\Client).

I'm not sure if this is a version of guzzle issue or what but it is currently preventing me from making any request using this library which is a shame. I noticed that the package only mentions the guzzle library in composer's suggests which doesn't enforce version so i'm leaning more towards it being related to that.

Thanks for any input on this, and if you need anymore information just let me know

Thank you for pointing me on this. It is indeed an error coming from requiring Guzzle 6.
Do you know, why the Facebook SDK is using guzzle 6 when the requier-dev is clearly saying ~5.0 ?
This looks like an composer misbehaviour. I will follow up on this in the composer community, thank you very much!
https://github.com/composer/composer/issues/6250

Upon searching through the closed issues for this repository i found this resource which helped me solve this issue:

https://github.com/facebook/php-graph-sdk/issues/627

Within this issue there is a link to a class that is a wrapper around guzzle 6, which implements the guzzle 5 interface, allowing you to use guzzle 6 with this library.

It seems that this issue is known by the developers and it is even on the road map to add Guzzle 6 support. So in the meantime using the wrapper contained in the above link is probably your best workaround.

@klausbreyer @madbriller what about mention in the README that v5 only support Guzzle v5, and adding a link to @SammyK's great post about using Guzzle v6?

@yguedidi good idea. will do this.

Just ran into the same issue.

The problem is that graph-sdk only requires Guzzle 5 in require-dev, so you can install Guzzle 6 through a regular require in your main project.

Graph SDK then detects the presence of the GuzzleHttp\Client class, assumes it is Guzzle 5 and goes on to use it incorrectly, triggering the fatal error mentioned above.

For me, the quick fix was to just tell Graph SDK to not use Guzzle but instead curl or stream. You can do this by passing an option when creating your Facebook\Facebook object:

$facebook = new Facebook\Facebook(['http_client_handler' => 'stream']);

Closing as the warning is added in the README.

@janhapke 's answer is the easiest work around. Used it today and got expected results.

@janhapke Thanks for the quick fix , still working at this date .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SammyK picture SammyK  路  8Comments

leoapsilva picture leoapsilva  路  6Comments

severin-bruhat picture severin-bruhat  路  3Comments

mohsenshakibafar picture mohsenshakibafar  路  4Comments

sr-expert picture sr-expert  路  5Comments