YouTube embed gives "restricted from playback on certain sites" error despite API metadata indicating otherwise
Asked Answered
S

7

12

I am trying to have my client application filter out videos that do not allow embedding. My understanding here is that there is no way to limit the feed (i.e. format=5 is insufficient) to do this and that I must check the properties of the entry myself, for the <yt:accessControl> tag and the <app:control> and <yt:state> tags.

This isn't working for me.

For example, this video: https://www.youtube.com/watch?v=waxat-_tRH8

doesn't embed: https://www.youtube.com/embed/waxat-_tRH8

even though the API returned data indicates (as far as I can tell) that it should be able to embed: https://gdata.youtube.com/feeds/api/videos/waxat-_tRH8?v=2

The entry does not contain any <yt:noembed> tag (see prior question) and the <media:restriction type='country' relationship='deny'>ME DE RS</media:restriction> does not explain this since I am in the US (see prior question) (see prior question).

What am I missing here?

EDIT: The embed link above works in my web browser, but not in my client app's WebView....!?

Stepsister answered 15/11, 2012 at 22:38 Comment(1)
dl.dropbox.com/u/6097787/test.html Works fine if you view it on Dropbox. Does not work if you save it to disk and open it as a file.Stepsister
D
9

Certain videos have a domain-level whitelist or blacklist applied to them. This is done at the discretion of the content owner.

If there is a whitelist or a blacklist, and the domain of the embedding site can't be determined (perhaps because of there not being a real referring domain in the case of your native application), then the default behavior is to block playback.

This blog post has a bit more detail as well: http://youtube-eng.blogspot.co.uk/2011/12/understanding-playback-restrictions_28.html

Dichotomous answered 19/11, 2012 at 22:15 Comment(5)
Thanks Jeff. A few followups: 1. Is there anything I can do in order to be allowed to play these videos? 2. If not, is there any way to determine these restrictions through the API, before loading the embed? As it is, I have a very bad user experience due to presenting these non-playable videos.Stepsister
Unfortunately, no. That specific video can only be played when it's embedded on a real website with a real referring URL, due to the way domain white/blacklisting works. And no, we don't expose those lists via the API. It's a longstanding feature request, though.Dichotomous
Jeff, is domain-level restriction accessible via API v3 now? any workarounds?Blakey
I don't believe it's returned in the v3 API response, but I no longer work on the API and am not authoritative.Dichotomous
hmm after 8years no solution, what about getting thumbnails from the stream?Molality
H
9

As Jeff Posnick pointed out, some videos have blacklists. If you try and request a video with a blacklist from an app and not a web page, you will see this error message:

"This video contains content from ___. It is restricted from playback on certain sites."

It's likely your app is NOT blacklisted, and that you're being blacklisted incorrectly. To fix this, you need to supply your Youtube API request with an origin (as atulkhatri pointed out).

In your request header for the Youtube video, set Referer to the domain in which you intend to be making the call from, (for ex. the domain of your app's corresponding website). If you don't have a domain, you could easily write some other domain, and that might work too.

  • For Android (Java), you can see an example here.

  • For iOS, look above

  • For React Native, you can use the origin prop on the component to your domain (origin is mentioned in the docs but doesn't tell you much about it).

  • Here is another example of the same issue in a browser when an extension blocked the Referer header from being sent for good measure.

This answer works for the V3 API of Youtube.

Hazardous answered 22/9, 2016 at 22:56 Comment(7)
I tried embedding a video on my site (currently it's local so only accessible through IP), and I'm facing the same issue. How can I changet the Referrer in a browser. All I have is the iframe embed code. Thanks.Delagarza
@Delagarza It's possible working locally may cause you this problem. You can also take a look at this page to get more info and see whether your browser may be a part of the problem as well.Hazardous
@JakeNelken Thanks for the attribution. Appreciate that.Buna
@JakeNelken I used this method to play embed restricted videos in my .NET application by adding the referer. Recently this stopped working. /embed videos don't play at all now, just show up as a black screen, no player is loading, so I thought it was a flash issue but /v/ links play just fine, but the restriction bypass doesn't work anymore. You had any experience with this?Boating
@Boating The app I used this trick for seems to show videos just fine still. If you discover how to fix it on your end please let us know. I doubt you have been specifically blacklisted but that's also a possibility (which in that case would break your videos from only 1 source -- not all videos with blacklists).Hazardous
@JakeNelken I fixed my issue. FEATURE_BROWSER_EMULATION was the ticket. msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspxBoating
@Hazardous Running locally was the cause in my case. Thanks for pointing that out.Amity
K
6

Actually, if you embed your video here:

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default

Like this:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<iframe width="420" height="315" src="https://www.youtube.com/embed/waxat-_tRH8" frameborder="0" allowfullscreen></iframe>
</body>
</html>

It actually is playable. So the problem actually comes back to why it works on website but not iOS mobile app?

Then I found out about this post:

http://support.metacdn.com/hc/en-us/articles/204513985-Video-Player-Embed-Restriction

It explains that the embed could be restricted due to lack of HTTP header "Referer" field.

So after setting the refer field, this video will be playing in iOS app:

let youtubeURL = NSURL(string: "https://www.youtube.com/embed/YQHsXMglC9A?autoplay=1") 
let youtubeRequest = NSMutableURLRequest(URL: youtubeURL!) 
youtubeRequest.setValue("https://www.youtube.com", forHTTPHeaderField: "Referer") 
webView.loadRequest(youtubeRequest)

Wala, it works now!

Are you happy? cause I am happy. :)

Kial answered 23/2, 2016 at 3:17 Comment(4)
How can we do the same for android? I am using ionic framework iframe is working fine on browser but not on android. On android it simply show message 'Restricted from playback on certain sites'Dimidiate
Sorry @user1188867, I am not familiar with Android, you may try search with "how to modify HTTP Referer field in Android", it could be the same cause.Kial
still not working for some id, please can anyone confirm it is working for video id=5IJ14RAqz3sMcdonnell
@Dimidiate please, have a look at my answerBenzol
B
3

You can use this answer. This worked perfectly in my case-

Adding origin in player vars as https://www.youtube.com

See this answer

Buna answered 3/4, 2016 at 10:38 Comment(1)
for me i had to add the httpsShaquana
B
1

For those who experience the same issue in webView on Android. I fixed that by adding the referer header field similarly to what @RainCast did in her answer.

 Map<String, String> extraHeaders = new HashMap<>();
 extraHeaders.put("Referer", "http://youtube.com");
 String url = "https://www.youtube.com/embed/dQw4w9WgXcQ";

 webView.loadUrl(url, extraHeaders);

It works for pure URL, but I don't know how to pass those parameters while injecting iFrame in the webView.

Benzol answered 3/10, 2017 at 22:57 Comment(0)
C
0

Add player vars while initializing youtube sdk:

NSDictionary *playerVars = @{
                             @"origin" : @"http://www.youtube.com",
                             };
[self.playerView loadWithVideoId:@"videoid" playerVars:playerVars];

Enjoy!

Corrosive answered 31/1, 2018 at 11:14 Comment(0)
O
-1

try like this instead

<iframe width="300" height="200" src="www.youtube.com/embed/<video-id>?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
Ornithischian answered 30/11, 2016 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.