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

时间:2015-11-16 13:04:29

标签: youtube-data-api

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

2 个答案:

答案 0 :(得分:1)

我找到了与此相关的内容,请检查

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

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

检查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

答案 1 :(得分:0)

这就是我所做的:

var myWebClient = new WebClient();
var responseString = myWebClient.DownloadString(" https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId + "&key=your_api_key_here");

var parsedResponseString = JObject.Parse(responseString);
JToken token = parsedResponseString["items"][0]["contentDetails"]["contentRating"];

if (token != null) {
  // there is no "contentRating" so no age restriction because "ytRating", if present, would be inside of "contentRating"

}