我正在开发YouTube数据API v3。
我想知道如何检查视频是否已被禁用或被YouTube删除。
例句: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>"
}
}
]
}
I tried this
https://www.googleapis.com/youtube/v3/videos
?part=id
&key=[mykey]
&id=dHt_6Z2OaZI
但它没有工作,仍然给出结果
在您发布的结果中有一个status
字段。我认为与你想要的最密切相关的子域是uploadStatus
。当我对该视频执行API调用时,我得到:
"status": {
"uploadStatus": "rejected",
"rejectionReason": "uploaderAccountSuspended",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}
从文档中,以下是uploadStatus
的可能值:
- 拒绝
视频成功上传和处理后,用户应该可以访问(假设它也是公共的)。因此,您应该检查状态是否为"拒绝"或"删除"。
如果有人仍然对这个问题感兴趣:
现在ContentDetails的项目包括RegionRestriction对象。你必须分析它,看看视频是否可用-这里是详细信息:文档
一般如果RegionRestriction。Blocked包含你正在观看的国家,那么视频对你来说是不可用的(类似地,你可以分析RegionRestriction.Allowed)。