使用 YouTube API v3 检查视频是否有年龄限制

Art*_*eek 4 youtube-data-api

有没有办法使用 YouTube API v3 来检查视频是否有年龄限制?查看文档我无法确认这一点。

len*_*nin 7

我发现了一些与此相关的内容,请检查

 https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id={VIDEO_ID}&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)

替换VIDEO_ID为您要检查的视频 ID。

API响应

{
 "kind": "youtube#videoListResponse",
 "etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/el3Y0P65UwM366CJD3POX-W4y0c\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "kind": "youtube#video",
   "etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/Rn64PVwC0Uhr4xp41vDOqygjJ9c\"",
   "id": "VIDEO_ID",
   "contentDetails": {
    "duration": "PT10M6S",
    "dimension": "2d",
    "definition": "hd",
    "caption": "false",
    "licensedContent": false,
    "contentRating": {
     "ytRating": "ytAgeRestricted"
    }
   }
  }
 ]
}
Run Code Online (Sandbox Code Playgroud)

检查一下ytRating,它有价值ytAgeRestricted,意味着该视频有年龄限制。

来自 Youtube-API 文档

contentDetails.contentRating.ytRating : string
       A rating that YouTube uses to identify age-restricted content.
       Valid values for this property are: ytAgeRestricted
Run Code Online (Sandbox Code Playgroud)