Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Display 6 videos from our YouTube channel using a search term

$
0
0

Can anyone illustrate how to resolve the following errors and allow me to authenticate through the oAuth client ID to return 6 videos from our youtube channel using a search term?

POST https://accounts.google.com/_/IdpIFrameHttp/cspreport/fine-allowlist 400 (Bad Request)Understand this errorAIcb=gapi.loaded_0?le=scs:169

GET https://content.googleapis.com/discovery/v1/apis/youtube/v3/search?pp=0&fields=kind%2Cname%2Cversion%2CrootUrl%2CservicePath%2Cresources%2Cparameters%2Cmethods%2CbatchPath%2Cid&key=API-KEY 404 (Not Found)

cb=gapi.loaded_0?le=scs:153 Uncaught{error: 'idpiframe_initialization_failed', details: 'You have created a new client application that use…i/web/guides/gis-migration) for more information.'}details:"You have created a new client application that uses libraries for user authentication or authorization that are deprecated. New clients must use the new libraries instead. See the Migration Guide for more information."error: "idpiframe_initialization_failed"

// Load the Google API client libraryfunction loadClient() {    import("https://apis.google.com/js/api.js").then(() => {    gapi.load('client', initialize);    })}// Initialize the API clientfunction initialize() {    gapi.client.init({'apiKey': 'API-KEY','clientId': 'CLIENT-ID.apps.googleusercontent.com','scope': 'https://www.googleapis.com/auth/youtube.readonly','discoveryDocs': ['https://www.googleapis.com/discovery/v1/apis/youtube/v3/search']    }).then(function () {        // Call the API to search for videos        searchVideos('SEARCH-TERM');    });}// Search for videos using the YouTube APIfunction searchVideos(searchTerm) {    return gapi.client.youtube.search.list({'part': 'snippet','q': searchTerm,'type': 'video','maxResults': 6    }).then(function(response) {        displayVideos(response.result.items);    }, function(error) {        console.error('Error: '+ error);    });}// Display videos on the WordPress pagefunction displayVideos(videos) {    const videoContainer = document.getElementById('video-container');    videoContainer.innerHTML = '';    videos.forEach(video => {        const videoElement = document.createElement('iframe');        videoElement.src = 'https://www.youtube.com/embed/'+ video.id.videoId;        videoElement.width = '300';        videoElement.height = '200';        videoElement.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';        videoElement.allowFullscreen = true;        videoContainer.appendChild(videoElement);    });}// Load the Google API client library on page loadwindow.onload = loadClient;// JavaScript Document
<div id="video-container"> </div>

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>