Youtube iframe api getVideoData removed, how to get the title?

Here, in Nov 13, I received a call from a client where the youtube player no longer worked, after a quick search in the dev tool, an error occurred

Uncaught TypeError: a.getVideoData is not a function 

After a quick look at what the Player object was in, where is the no function for getVideoData.

GetVideoData is a way to get the name of the video, but how can I get the name now? And are there any articles from Google changing about this?

+5
source share
2 answers

To get the title of the video, you can request the YouTube v3 data API :

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

To do this, you need to register on the Google Cloud Console and create an API key (it is free). You can restrict the use of the API key only on your website so that you can safely publish it in your JS / html source code if others cannot make requests on your behalf. Be sure to enable the YouTube Data 3 API in the console, otherwise your queries will return errors.

The above request will return a JSON representation of information about the video you are interested in (part of snippet ). Let's say you parse JSON into an object called result . Then you can get the title of the video using

 result.items[0].snippet.title 
+3
source

getVideoData() seems to be back (December 2017). So try again!

0
source

Source: https://habr.com/ru/post/1273349/


All Articles