Are you seeing the error message "Could not retrieve the oEmbed resource" in you Drupal Media library and don't know what that means and how to fix it?
It was the same for me. So I had a look into the code.
TL;DR:
At least one of your oEmbed media entities has a wrong URL in 95% of the cases ;)
Into details:
The Exception can be found at core\modules\media\src\OEmbed\ResourceFetcher.php, Line 74:
try {
$response = $this->httpClient->request('GET', $url, [
RequestOptions::TIMEOUT => 5,
]);
}
catch (TransferException $e) {
throw new ResourceException('Could not retrieve the oEmbed resource.', $url, [], $e);
}
In most cases it simply means, that an oEmbed resource could not be found. For example because one of the following reasons:
- The media URL is broken
- The provider / URL is unknown
- The resource is now private or was removed (e.g. for YouTube videos)
In all such cases, oEmbed can't fetch resources, like thumbnails and fails with this unclear error message!
So check your media library for broken oEmbed URLs!
Other possible reasons
The reason above is the typical one, but there might be other reasons:
You're offline
Another reason might be, that the remote servers for fetching the oEmbed information is not reachable, e.g. because you're offline.
Wrong oembed_providers_url config value
The config value of media.settings oembed_providers_url
is wrong.
Check it by running the following drush command:
drush cget media.settings oembed_providers_url
which should typically return
if you didn't need modify it.
You may set the value by using drush cset ...
These issues are about improving the error message and logging:
- https://www.drupal.org/project/drupal/issues/2972846
- https://www.drupal.org/project/drupal/issues/3186977
Please help to get it fixed! :)