问题
After searching, here on stackoverflow and in the API documentation, I can't figure out how I'm going to search for a movie trailer in youtube with a variable. I have this method in my service URL:
getTrailer(): Observable<Object> {
let url =
' https://www.googleapis.com/youtube/v3/search?part=snippet&q=guy&key=(mykey)'
return this.http.get(url).pipe(
map(res => {
return res['items'];
})
);
}
And back in the component subscription I can see this items array, but Im failing to understand how to fetch a trailer video according to an users input...Can someone give me a hint?
回答1:
Use the query parameters, they are explained here https://developers.google.com/youtube/v3/docs/search/list?apix_params=%7B%22part%22%3A%22snippet%22%2C%22maxResults%22%3A25%2C%22q%22%3A%22surfing%22%7D
First of all I would use the topicId=/m/02vxn
(Movies).
And add q=trailer
as term.
That ends up in a request url like this
https://www.googleapis.com/youtube/v3/search?part=snippet&q=trailer&topicId=%2Fm%2F02vxn&key=[YOUR_API_KEY]
来源:https://stackoverflow.com/questions/59058308/search-movie-trailers-with-youtube-api-and-angular