检查视频是否可用

时间:2015-07-16 18:29:35

标签: youtube youtube-api youtube-data-api

我正在使用YouTube数据API v3。

我想知道如何检查视频是否已被YouTube禁用或删除。

E.g: https://www.youtube.com/watch?v=dHt_6Z2OaZI

https://www.googleapis.com/youtube/v3/videos?id=dHt_6Z2OaZI
&part=snippet,contentDetails,player,statistics,status
&key=[mykey]

我无法从API中获得任何想法。

{
"kind": "youtube#videoListResponse",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/Y7032cCbQSAurzEiVMjdFYzamtg\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/2FORRsUGqbS1nvQK3AR1PfmiN7I\"",
"id": "dHt_6Z2OaZI",
"snippet": {},
"contentDetails": {
"duration": "PT1H31M1S",
"dimension": "2d",
"definition": "sd",
"caption": "false",
"licensedContent": false
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
},
"statistics": {
"viewCount": "301",
"likeCount": "0",
"dislikeCount": "0",
"favoriteCount": "0",
"commentCount": "0"
},
"player": {
"embedHtml": "<iframe width=\"640\" height=\"360\" src=\"//www.youtube.com/embed/dHt_6Z2OaZI\" frameborder=\"0\" allowfullscreen></iframe>"
}
}
]
}

我试过这个

https://www.googleapis.com/youtube/v3/videos
?part=id
&key=[mykey]
&id=dHt_6Z2OaZI

但它不起作用,仍然会给出结果。

2 个答案:

答案 0 :(得分:2)

您发布的结果中有status字段。我认为与你想要的最密切相关的子字段是uploadStatus。当我为该视频执行API调用时,我得到:

"status": {
    "uploadStatus": "rejected",
    "rejectionReason": "uploaderAccountSuspended",
    "privacyStatus": "public",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": true
   }

documentation开始,以下是uploadStatus的可能值:

  
      
  • 已删除
  •   
  • 失败
  •   
  • 已处理
  •   
  • 拒绝
  •   
  • 上传
  •   

视频成功上传和处理后,用户应该可以访问它(假设它也是公开的)。因此,您应该检查状态是“被拒绝”还是“已删除”。

答案 1 :(得分:0)

万一有人对此问题仍然感兴趣:

现在,Item的ContentDetails包含RegionRestriction对象。您必须对其进行分析以查看视频是否可用-以下是详细信息:documentation

通常,如果RegionRestriction.Blocked包含您正在查看的国家/地区,则该视频不可用(同样,您可以分析RegionRestriction.Allowed)。