使用 YouTube API 检查视频是否可嵌入 [英] Use the YouTube API to check if a video is embeddable

查看:22
本文介绍了使用 YouTube API 检查视频是否可嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 YouTube Data API v3 确定是否可以嵌入 YouTube 视频,从类似问题的答案中,我注意到视频的 status.embeddable 属性,对于这样的请求:

I'm trying to figure out if a YouTube video is embeddable using the YouTube Data API v3, from answers to similar questions I noticed the status.embeddable property of videos, for a request like this:

https://www.googleapis.com/youtube/v3/videos?id=63flkf3S1bE&part=contentDetails,status&key={MY_API_KEY}

回复如下

{
    "kind": "youtube#videoListResponse",
    "etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/ctZQYtBcOuMdnQXh8-Fv1EbS_VA\"",
    "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 1
    },
    "items": [
        {
            "kind": "youtube#video",
            "etag": "\"ksCrgYQhtFrXgbHAhi9Fo5t0C2I/Cd8aGZD09NPuGYNumIEozZs2S90\"",
            "id": "63flkf3S1bE",
            "contentDetails": {
                "duration": "PT8M23S",
                "dimension": "2d",
                "definition": "hd",
                "caption": "false",
                "licensedContent": false,
                "projection": "rectangular"
            },
            "status": {
                "uploadStatus": "processed",
                "privacyStatus": "public",
                "license": "youtube",
                "embeddable": true,
                "publicStatsViewable": true,
                "madeForKids": false
            }
        }
    ]
}

status 下的 embeddable 参数返回为 true,但是该视频实际上并不是可嵌入的,可以看出 此处.

The embeddable parameter under status is returned as true, HOWEVER this video is not actually embeddable, as can be seen here.

实际使用 iframe API 嵌入视频时,还有更详细的错误消息:

When actually embedding the video using the iframe API, there is a more detailed error message as well:

视频不可用该视频包含来自国际奥委会的内容,该委员会已阻止其在本网站或应用程序上显示.在 YouTube 上观看

Video unavailable This video contains content from International Olympic Committee, who has blocked it from display on this website or application. Watch on YouTube

我不知道如何从 YouTube 数据 API 检测到这种情况 - 谁能帮忙?

I don't see how it is possible to detect this case from the YouTube Data API - can anyone help out?

推荐答案

这个答案中使用了其他选项:

在这里,您可以使用以下网址:

Here, you can use the following URL:

https://www.youtube.com/get_video_info?video_id=<VIDEO_ID>

其中 VIDEO_ID 是您要检索信息的 YouTube video_id.

Where VIDEO_ID is the YouTube video_id you want retrieve the information.

在这种情况下,一旦您收到响应,您将看到一个名为playabilityStatus.status"的属性.

In this case, once you get the response, you'll see a property called "playabilityStatus.status".

以下是回复的摘录:

 "playabilityStatus": {
        "status": "UNPLAYABLE",
        "reason": "The video is not available",
        "errorScreen": {
            "playerErrorMessageRenderer": {
                "reason": {
                    "simpleText": "The video is not available"
                },

除了 johnh10 的回答之外,在 YouTube 网页中看到的一些结果并不总是在 API 中显示/可用.

Additional to johnh10's answer, some of the results saw in the YouTube webpage is not always shown/available in the APIs.

这篇关于使用 YouTube API 检查视频是否可嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆