Hey! so long story short, I'm trying to create a program on wix code where its able to search through a particular Youtube channel to find videos specified by certain keywords inputted by a dynamic page. I got as far as being able to create the url but I am not sure how to get the video ids of each search result and display the videos with the Youtube API. How do I get this to work?
This is my first time with Wix code and javascript. Any help would be appreciated!
Here is my attempts:
The dynamic page code:
import {getVideos} from 'backend/videoSearch.jsw'; $w.onReady(function () { $w("#teamDataset").onReady(() => { let name = $w("#teamDataset").getCurrentItem(); $w('#text5').text = name; let name1 = name.title; getVideos(name1) .then(response => { console.log(response[0].videoId) }) }); }) the url:
import {fetch} from 'wix-fetch'; export function getVideos(x) { let url = "https://youtube.googleapis. com/youtube/v3/search?part=snippet&channelId=UC6G_LCSmfd9q34BMao87E0g&maxResults=10&q="+x+"&key=[my-api]"; console.log("Url: " + url); return fetch(url, {method: 'get'}) .then(response => response.json) }
Hi,
Try:
//backend //... return fetch(url, {method: 'get'}) .then(response => response.json()) .then(r => r?.items)
//front-end //... getVideos(encodeURI(name1)) .then(response => { if(response.length){ console.log(response[0].id.videoId); } })