如何使用YouTube API检查视频是否受到限制?

时间:2016-08-04 08:13:42

标签: youtube-data-api

例如,在嵌入此YouTube video时,我们会收到This video contains content from... who has blocked it from display on the website错误消息。

如何使用API​​查找视频是否被阻止?

我找到的最近参数是statuscontentDetails

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

没有返回任何关于限制的指示:

   "contentDetails": {
    "duration": "PT2M",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": true,
    "projection": "rectangular"
   },
   "status": {
    "uploadStatus": "processed",
    "privacyStatus": "public",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": false
   }

2 个答案:

答案 0 :(得分:2)

检查区域contentDetails.regionRestriction或受年龄限制的内容contentDetails.contentRating或合作伙伴contentDetails.licensedContent声明的内容是否受到限制?我也在这里推测。

修改:您可以使用它来检查它是否也可嵌入{。{1}}。

答案 1 :(得分:0)

确保正确设置“零件”。这是必填字段,您可能有“ snippet here”,并且需要“ contentDetails”。 (或两者均为“ snippet,contentDetails”)

示例:

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"
   }
  }
 ]
}

仅在美国和西班牙允许这样做