Youtube oEmbed without www prefix shows "403 Forbidden" error and shows "Could not retrieve the oEmbed resource."

Created on 17 December 2020, over 3 years ago
Updated 15 September 2023, 9 months ago

Problem/Motivation

Youtube oEmbed without www prefix shows "403 Forbidden" error and shows "Could not retrieve the oEmbed resource."

Since about december 14th 2020 any oEmbed for youtube that we have where the URL does not contain www. will give "Could not retrieve the oEmbed resource." when adding it as a new media item. Existing items without www. will give a 403 error in the watchdog and not load.

This seems to be an upstream issue and I'm not sure we can do anything about this, but posting here anyway to see if people can come up with something.

Had a discussion with @seanB on slack and posting a shortened transcript of that

lendude Dec 15th at 8:43 PM
I’m getting an error when adding youtube video’s that don’t have www. in the URL, but they work fine with the www. added
so https://youtube.com/watch?v=mS6fFzsHKUc => Could not retrieve the oEmbed resource.
https://www.youtube.com/watch?v=mS6fFzsHKUc => no problems
Anybody else seeing this? (edited)
24 replies

seanb 23 hours ago
Hmm according to https://oembed.com/providers.json
{
"provider_name": "YouTube",
"provider_url": "https:\/\/www.youtube.com\/",
"endpoints": [
{
"schemes": [
"https:\/\/*.youtube.com\/watch*",
"https:\/\/*.youtube.com\/v\/*",
"https:\/\/youtu.be\/*"
],
"url": "https:\/\/www.youtube.com\/oembed",
"discovery": true
}
]
},

seanb 23 hours ago
Translates to the following regexes
https:\/\/.*\.youtube\.com\/watch.*
https:\/\/.*\.youtube\.com\/v\/.*
https:\/\/youtu\.be\/.*

seanb 23 hours ago
Which seem to require a subdomain for youtube.com

seanb 23 hours ago
But the non-www URLs of youtube redirect to the www version, and also the share link https://youtu.be/* is supported, so most users probably wont run into this.

lendude 23 hours ago
Yeah but the thing is, it used to work just fine

lendude 23 hours ago
As far as I can tell, if no valid scheme is found, it will try to parse the oembed URL from the content youtube url, and that parsing results in a http and not https url, which results in a 403 because it only supports https

seanb 23 hours ago
Ah, yes it parses the application/json+oembed link in the body, not sure why that returns a http URL. Maybe youtube changed something?

lendude 23 hours ago
Yeah that is my guess :shrug:

seanb 22 hours ago
:disappointed:

Steps to reproduce

Proposed resolution

Remaining tasks

Improve the error message. "Could not retrieve the oEmbed resource." doesn't tell enough to understand what's going on and how to fix it!

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Media 

Last updated 1 day ago

Created by

🇳🇱Netherlands Lendude Amsterdam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024