opensea-php icon indicating copy to clipboard operation
opensea-php copied to clipboard

Uncaught TypeError: Return value of OwenVoke\OpenSea\Api\Asset::all() must be of the type array, string returned

Open ADSoftTeam opened this issue 3 years ago • 5 comments

Description

Fatal error: Uncaught TypeError: Return value of OwenVoke\OpenSea\Api\Asset::all() must be of the type array, string returned

Environment

  • PHP 7.4:

Hi. Simple code

require_once __DIR__ . '/vendor/autoload.php';

use OwenVoke\OpenSea\Client;

$client = new Client();
$assets = $client->assets();

print_r($assets->all());

I find error - CloudFlare blocked status 404 and error code: 1020 I think - need add exception if get errors

ADSoftTeam avatar Mar 22 '22 10:03 ADSoftTeam

If it's a 404, this definitely should have thrown an exception (depending on your HTTP client package). Not sure why it wouldn't...

I'll try and replicate this later. 👍🏻

owenvoke avatar Mar 23 '22 09:03 owenvoke

I lied - 403 error

ADSoftTeam avatar Mar 23 '22 14:03 ADSoftTeam

Ah, 403 should still error though. 🤔 Just to check, are you using this package with Guzzle?

owenvoke avatar Mar 23 '22 14:03 owenvoke

Yes Clear project - instal: composer require owenvoke/opensea guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 and simple example

ADSoftTeam avatar Mar 23 '22 14:03 ADSoftTeam

Not entirely sure why the 403 error isn't being converted to an exception, however, it looks like the /assets endpoint now requires an API key. Not sure if you already have one, but if not, you can request one here.

~~I'll look into why Guzzle isn't throwing an exception over the next few days. 👍🏻~~ Looks like HTTPlug doesn't implement exception handling by default (which I thought it did as Guzzle usually does). Looks like I'll need to implement this similarly to how the PHP GitHub API package does.

owenvoke avatar Mar 24 '22 12:03 owenvoke