I am working on a YouTube clone from YouTube API v3, whereas I need to related videos list based on the current playing video’s videoId.
async function getApiData(videoId) {
const res = await apiRequest('/search', {
params: {
part: 'snippet',
videoCategoryId: videoId, // relatedToVideoId : videoId
maximumResult: 10,
type: 'video'
}
})
console.log("res", res)
return res;
}
In the params, I have passed videoCategoryId/relatedToVideoId, in different requests.
but it sends an error message.
What would be the correct way to get a related video list from the YouTube API based on the videoId?
Thanks for your support
2
Answers
I think to retrieve related videos based on a given
videoId
using the YouTube API v3, you should use therelatedToVideoId
parameter instead ofvideoCategoryId
.The
videoCategoryId
parameter is used for filtering videos by category, not for retrieving related videos.I add sample code below:
****strong text https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&relatedToVideoId=SHT0y9Gq_rk&key={your-key}
this method do not working why?