Now the YouTube return min. width and height. How can adjust the GET call to change the return html
?
e.g:
"html": "<iframe width=\"400\" height=\"260\" src=\"https://www.youtube.com/embed/kFz9afj8lu0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
Current https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=kFz9afj8lu0
{
"title": "Can You Actually Game in 8K? (RTX 3090 Gameplay!)",
"author_name": "Marques Brownlee",
"author_url": "https://www.youtube.com/c/mkbhd",
"type": "video",
"height": 113,
"width": 200,
"version": "1.0",
"provider_name": "YouTube",
"provider_url": "https://www.youtube.com/",
"thumbnail_height": 360,
"thumbnail_width": 480,
"thumbnail_url": "https://i.ytimg.com/vi/kFz9afj8lu0/hqdefault.jpg",
"html": "<iframe width=\"200\" height=\"113\" src=\"https://www.youtube.com/embed/kFz9afj8lu0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
}
Looks like there is an oEmbed spec: https://oembed.com
If you look down in section
2.2. Consumer Request
You will note there are maxwidth
and maxheight
options.
Add &maxwidth=400&maxheight=260
to your GET request, like so:
https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=kFz9afj8lu0&maxwidth=400&maxheight=260
This will return the following:
{
"title": "Can You Actually Game in 8K? (RTX 3090 Gameplay!)",
"author_name": "Marques Brownlee",
"author_url": "https://www.youtube.com/c/mkbhd",
"type": "video",
"height": 225,
"width": 400,
"version": "1.0",
"provider_name": "YouTube",
"provider_url": "https://www.youtube.com/",
"thumbnail_height": 360,
"thumbnail_width": 480,
"thumbnail_url": "https://i.ytimg.com/vi/kFz9afj8lu0/hqdefault.jpg",
"html": "\u003ciframe width=\u0022400\u0022 height=\u0022225\u0022 src=\u0022https://www.youtube.com/embed/kFz9afj8lu0?feature=oembed\u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\u0022 allowfullscreen\u003e\u003c/iframe\u003e"
}
The html
property, after decodeURIComponent
, now looks like your example:
<iframe width=\"400\" height=\"225\" src=\"https://www.youtube.com/embed/kFz9afj8lu0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With