This question already has an answer here:
I am trying to feed my django page with some resource I am getting from somewhere else.
inside feed, I have youtube videos with url like: https://www.youtube.com/watch?v=A6XUVjK9W4o
once I added this into my page, video doesnot show up saying:
Refused to display 'https://www.youtube.com/watch?v=A6XUVjK9W4o' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Then I said, well, what if I change watch
to embed
. Then youtube player shows up, but no video, saying:
does anyone have a clue how I get this to work?
I am showing in html like this:
<iframe width="420" height="315"
src="{{vid.yt_url}}">
</iframe>
I googled almost for an hour, no sign of success. I tried to append &output=embed
.. nada..
Youtube url in
src
must have and useembed
endpoint instead ofwatch
so for instance lets say you want to embed this youtube videohttps://www.youtube.com/watch?v=P6N9782MzFQ
(browser's url) you should useembed
endpoint so the url now should be something likehttps://www.youtube.com/embed/P6N9782MzFQ
, use this value as url in thesrc
attribute inside the iframe tag in your HTML code, for example:<iframe width="853" height="480" src="https://www.youtube.com/embed/P6N9782MzFQ" frameborder="0" allowfullscreen ng-show="showvideo"></iframe>
So just replace
https://www.youtube.com/watch?v=
withhttps://www.youtube.com/embed/
and of course check for your video's ID in this sample my video ID isP6N9782MzFQ
Along with the embed, I also had to install the Google Cast extension in my browser.
You must ensure the URL contains embed rather watch as the
/embed
endpoint allows outside requests, whereas the/watch
endpoint does not.If embed no longer works for you try with /v instead.
You only need to copy from youtube Embed section (click on SHARE below the video and then EMBED and copy the entire iframe)