I'm working in node on a server and I'm trying to use the YouTube Api to get a video url. The particular url isn't important, this is more of just an exercise. As far as I can tell with the docs, the best way to find a particular video is if it is associated with a channel or user. IE,
videoId
field, search with thatHowever, when I get to that point I feel like there should be a url to that video. The though process would be to send this url back to a front end to allow it to use some library to render the video.
QUESTION: Is there a better way to do this? If not, where am I missing the video URL,
In your return you should get a videoId
:
"id":
{
"kind": "youtube#video",
"videoId": "BsLvIF5c7NU"
}
edit: the return is actually just the id
:
"id": "BsLvIF5c7NU"
All you need to do is just append that to the standard url no?:
var url = `https://www.youtube.com/watch?v=${result.id.videoId}`;
Does that make sense?
edit: You could also use part=contentDetails
in which case the id
is under:
result.items.id
Depending on what you use in the part
param will change up the layout of what's returned.
Hope that helps you, dude.