Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube IFrame Player API getVideoData is removed: how to get title?

On November 13th, I got a call from a customer reporting that the YouTube player didn't work anymore. After a quick look in the dev tool, I found that there was an error:

Uncaught TypeError: a.getVideoData is not a function

Looking into what the player object was containing, I learned that there's no function getVideoData anymore.

The function getVideoData provided a way to get the video title. Now, how can I get the title?

Is there any article from Google about this change?

like image 281
user3173634 Avatar asked Nov 14 '17 09:11

user3173634


1 Answers

To get a video's title, you can query the YouTube Data API v3:

GET https://www.googleapis.com/youtube/v3/videos
    ?part=snippet
    &id=VIDEO_ID
    &key=YOUR_API_KEY

For that you need to sign up on the Google Cloud Console and create an API key (it's free). You can restrict the API key to only be used from your website, that way you can safely make it public in your JS source code/html code without others being able to make queries on your behalf. Make sure to enable the YouTube Data API v3 in the console as well, otherwise your queries will return errors.

The above query will return a JSON representation of the information on the video that you are interested in (the snippet part). Say you parse the JSON into an object called result. Then you can get the video title via

result.items[0].snippet.title
like image 56
paolo Avatar answered Sep 23 '22 14:09

paolo