Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chegmarco1989 opened this issue Jun 1, 2022 · 1 comment

Comments

@chegmarco1989
Copy link

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants