slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 47 forks source link

Fatal error when initializing using access token #42

Closed GordonZed closed 4 years ago

GordonZed commented 4 years ago

I had no issues authenticating as a private app, but I've switched to a public app (need app proxies) and implemented Oauth, and I'm successfully installing the app to my store and getting the access token, only to get an error when I actually try to initialize the client using an access token, as opposed to api key and password, which worked fine.

<br />
<b>Fatal error</b>:  Uncaught InvalidArgumentException: Header value must be scalar or null but Slince\Shopify\AccessToken provided. in /var/www/redacted-url.net/app/vendor/guzzlehttp/psr7/src/MessageTrait.php:190
Stack trace:
#0 [internal function]: GuzzleHttp\Psr7\Request-&gt;GuzzleHttp\Psr7\{closure}(Object(Slince\Shopify\AccessToken))
#1 /var/www/redacted-url.net/app/vendor/guzzlehttp/psr7/src/MessageTrait.php(197): array_map(Object(Closure), Array)
#2 /var/www/redacted-url.net/app/vendor/guzzlehttp/psr7/src/MessageTrait.php(162): GuzzleHttp\Psr7\Request-&gt;trimHeaderValues(Array)
#3 /var/www/redacted-url.net/app/vendor/guzzlehttp/psr7/src/MessageTrait.php(70): GuzzleHttp\Psr7\Request-&gt;normalizeHeaderValue(Object(Slince\Shopify\AccessToken))
#4 /var/www/redacted-url.net/app/vendor/slince/shopify-api-php/src/PublicAppCredential.php(43): GuzzleHttp\Psr7\Request-&gt;withHeader('X-Shopify-Acces...', Object(Slince\Shopify\AccessToken))
#5 /var/www/redacted-url.net/app/vendor/slince/shopify-api-php/src/Client.php(342): Slince\Shopify\PublicAppCredential-&gt;applyToR in <b>/var/www/redacted-url.net/app/vendor/guzzlehttp/psr7/src/MessageTrait.php</b> on line <b>190</b><br />

If this is a result of my own stupidity and not an issue, then please disregard and close this, but I'm at a loss at the moment so I'm not really sure.

   $credential = new Slince\Shopify\PublicAppCredential($access_key);

   $shopify = new Slince\Shopify\Client($credential, $shop_url, [
       'metaCacheDir' => 'tmp' // Metadata cache dir, required
   ]);
maximzasorin commented 4 years ago

Hello, looks like you did the right thing. This bug in the library (see #39) was fixed in the latest version 2.3.2 which was published today.

Try to update the library:

composer update slince/shopify-api-php
GordonZed commented 4 years ago

Sweet, thank you. I was starting to think it was maybe an issue with Guzzle, but shows how much I know.