Know if a video Youtube is unavailable with the API

情到浓时终转凉″ 提交于 2020-06-14 06:25:53

问题


Via the Youtube API, how can I detect if a video Youtube is unavailable (ex : https://www.youtube.com/watch?v=5nRZlcB2jPY) ?

Thanks


回答1:


You would make an API call for the video status.

https://www.googleapis.com/youtube/v3/videos?id=VIDEOID&part=status&key=APIKEY

Then check the uploadStatus in the json result:

"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true
}



回答2:


This is also partially possible without API. Let's say you want to see if the following video is available:

https://www.youtube.com/watch?v=esDJPiGu5x0

The ID of the video is shown as the GET parameter v. Use this one to request the following thumbnail:

https://img.youtube.com/vi/esDJPiGu5x0/0.jpg

If the content of the response has a length of 0 and/or the http response code by youtube.com is 404, then the video is not available anymore.



来源:https://stackoverflow.com/questions/32480047/know-if-a-video-youtube-is-unavailable-with-the-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!