I'm embedding a YouTube video in my website as follows:
<iframe src="https://www.youtube.com/embed/C_JiP-j2FwM?autoplay=1&loop=1" frameborder="0" allowfullscreen width="100%" height="100%"></iframe>
It works great but on my work computer, when I'm logged into Google Chrome with my work email, I get the following error:
An error occurred. Please try again later. (Playback ID: TMjivVwHlyxtQxnL) Learn More
This is expected. It's because my work email doesn't have permission to access YouTube. Here's the error I'm getting when I try to access it with my work email:
According to the DOM Inspector / Network tab requests to https://www.youtube.com/youtubei/v1/player?key=C_JiP-j2FwM are giving this error back:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
The code works because I can play the embedded video back in Incognito back just fine (because I'm not logged into my work email when I'm in Incognito).
Here's the code in it's full glory so people can reproduce the "problem" and see that it, in all likelihood, works great for them: https://jsfiddle.net/p3jz62uL/
What I'd like to be able to do is "catch" the error and change the behavior if it would occur. Maybe I'd remove the video all together or maybe I'd replace it with an image idk.