ricardofiorani / oembed

PHP OEmbed wrapper for well-known video platforms and services
MIT License
38 stars 7 forks source link

Fatal error: Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. #11

Open chegmarco1989 opened 2 years ago

chegmarco1989 commented 2 years ago

Hello.

I am trying to use this library under Laragon with the following example code and of course after installing it via composer:

<?php declare(strict_types=1);

use Your\PSR7Implementation\Uri;
use RicardoFiorani\OEmbed\OEmbed;

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

$service = new OEmbed();

$uri = new Uri('https://www.dailymotion.com/video/x804zfb?playlist=x6ymns');

$result = $service->get(
    $uri,
    480,
    300,
    ['omitscript' => true]
);

echo (string)$result; //will render the HTML (in case of "video" or "rich") or URL (in case of "photo")

And I get the following error:

Fatal error: Uncaught Http\Discovery\Exception\DiscoveryFailedException: Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors - No valid candidate found using strategy "Http\Discovery\Strategy\CommonClassesStrategy". We tested the following candidates: Http\Discovery\Strategy\CommonClassesStrategy::symfonyPsr18Instantiate, GuzzleHttp\Client, Http\Discovery\Strategy\CommonClassesStrategy::buzzInstantiate. - No valid candidate found using strategy "Http\Discovery\Strategy\CommonPsr17ClassesStrategy". We tested the following candidates: . in C:\laragon\www\vendor\php-http\discovery\src\Exception\DiscoveryFailedException.php:41 Stack trace: #0 C:\laragon\www\vendor\php-http\discovery\src\ClassDiscovery.php(85): Http\Discovery\Exception\DiscoveryFailedException::create(Array) #1 C:\laragon\www\vendor\php-http\discovery\src\Psr18ClientDiscovery.php(25): Http\Discovery\ClassDiscovery::findOneByType('Psr\\Http\\Client...') #2 C:\laragon\ in C:\laragon\www\vendor\php-http\discovery\src\Psr18ClientDiscovery.php on line 27

So why this error ??? Please, help me fix this error..

ricardofiorani commented 2 years ago

Hello @chegmarco1989, thank you for raising this issue.

The code you posted (that I guess you got from the example) won't work because your application doesn't meet the requirements described in the readme.

A PSR-18 implementation
A PSR-17 implementation of RequestFactory and UriFactory

The OEmbed construct uses Psr18ClientDiscovery and Psr17FactoryDiscovery to try to detect which adapter you have and use it, otherwise, you can override it by passing the adapter as arguments to the constructor.

The easiest way to solve it would be to run composer require ricardofiorani/guzzle-psr18-adapter or require on composer any other PSR-18 adapter of your choice.

Let me know if that helps.