E
E
Evgeny Romashov2021-05-12 17:06:05
JavaScript
Evgeny Romashov, 2021-05-12 17:06:05

How to display received data from youtube api in html as video?

Hello!

Please tell me how to display the received data from the youtube api on the html page.

const apiKey = 'my_key';
const url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=heroes%3&type=video&key=my_key';
const mainVideo = document.getElementById('main_video')

fetch(url).then(function(response) {
  response.text().then(function(text) {
    let newText = JSON.parse(text)
    	mainVideo.innerText = newText;
      console.log(newText)
  });
});


<aside class="video main-content-right" id="main_video">
                <h2>Video Here</h2>
                <iframe src="" id="myIframe"></iframe>
</aside>


Now displays as a string what the object is. And if you remove the json.parse method, then there will just be a lot of text. How to fix the situation, the data then comes ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
drawnofmymind, 2021-05-12
@drawnofmymind

Response data should be videoId
myIframe.src="videoId "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question