How to use YouTube API to check if a video is restricted?
Asked Answered
C

2

6

When embedding this YouTube video for example, we get This video contains content from... who has blocked it from display on the website error message.

How can I use the API to find if a video is blocked or not?

The nearest parameters I found are status and contentDetails:

GET https://www.googleapis.com/youtube/v3/videos?part=status&id=dYQ2IyMuPes&key={YOUR_API_KEY}

Which returns no indication about the restriction:

   "contentDetails": {
    "duration": "PT2M",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true,
    "projection": "rectangular"
   },
   "status": {
    "uploadStatus": "processed",
    "privacyStatus": "public",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": false
   }
Casey answered 4/8, 2016 at 8:13 Comment(2)
same post : #30191120Stocky
Similar question, however the answer doesn't solve my issue unfortunately.Casey
S
3

Check if it is restricted in the region contentDetails.regionRestriction or age-restricted content contentDetails.contentRating or content claimed by partner contentDetails.licensedContent? I am just speculating here too.

Edit: You can use this to check if it is embeddable too status.embeddable.

Sig answered 4/8, 2016 at 9:21 Comment(6)
Both status and contentDetails does not show any indication of the restriction. I've updated the question to make it more clear, thanks.Casey
You can access the video directly from browser right?Sig
The video works fine for me in browser (youtube.com). And your status response shows embeddable=true. I guess I cant figure it out, sorry! Good luck!Sig
Have you clicked on the link in the question and played the video?Casey
Yea, it is playing fine on both my android chrome browser and in my android youtube appSig
I see your error message when trying to view the sample embedded video from Japan. Geo-locked?Brader
J
1

Be sure to have the "part" set correctly. It's a required field and you probably have "snippet there" and you need "contentDetails". (or "snippet,contentDetails" for both)

Example:

GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=OoKpYXTmYak&key={YOUR_API_KEY}


{
 "kind": "youtube#videoListResponse",
 "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/Xn7P-qyclepPOIFp9Bn69FdtR-4\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "kind": "youtube#video",
   "etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/_vu8XkjotVqxtJKQ2peTcRK8TYE\"",
   "id": "OoKpYXTmYak",
   "contentDetails": {
    "duration": "PT1M41S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true,
    "regionRestriction": {
     "allowed": [
      "ES",
      "US"
     ]
    },
    "projection": "rectangular"
   }
  }
 ]
}

This is allowed in the US and Spain only

Jonquil answered 27/3, 2019 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.