Search movie trailers with youtube api and angular

大兔子大兔子 提交于 2020-02-06 09:07:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!