检查Youtube(api v3)上是否存在视频

问题描述:

当用户输入youtube网址时,我想确保视频是否存在于youtube上,以便我可以使用jquery嵌入并显示该视频.我发现的所有其他答案均不适用于我,因为它们适用于较旧的api版本.

When user inputs a youtube url, I want to make sure if the video exists on youtube so that I can embed and display it using jquery. Every other answers I found didnt worked for me, since they were for the older api versions.

如何检入API v3(最好不使用OAuth)?

How do I check in it API v3 (preferably without using OAuth)?

谢谢.

视频:列表将其传递给part ="id"和视频的ID.

Videos: list pass it part = "id" and the id of the video.

示例:

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

有效的将返回

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

   "kind": "youtube#video",
   "etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/yMdFb3bBbXC_5kG0I6NON02yC0U\"",
   "id": "b_bJQgZdjzo"
  }
 ]
}

无效的将返回

{
 "kind": "youtube#videoListResponse",
 "etag": "\"mPrpS7Nrk6Ggi_P7VJ8-KsEOiIw/fseqvds4o9r_b2TtUNVFskKrE9s\"",
 "pageInfo": {
  "totalResults": 0,
  "resultsPerPage": 0
 },
 "items": [
 ]
}

videos.list是一个公共电话,因此您只需要一个公共api密钥而不是Oauth.

videos.list is a public call so you just need a public api key not Oauth.