Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the YouTube API to check if a video is 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}

The response is the following

{
    "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
            }
        }
    ]
}

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

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

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

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

like image 844
JoGr Avatar asked Dec 23 '22 18:12

JoGr


1 Answers

Other option is used in this answer:

Here, you can use the following URL:

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

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

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

Here is a extract of the response:

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

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

like image 139
Mauricio Arias Olave Avatar answered Dec 28 '22 05:12

Mauricio Arias Olave