| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import 'whatwg-fetch';
- import querystring from 'querystring';
- _ = lodash;
-
- const KEY = 'AIzaSyDh641dLzxYexCASA3TdYMlc6zzS793ppQ';
- const ENDPOINT = 'https://www.googleapis.com/youtube/v3';
-
- const checkStatus = (response) => {
- if (response.status >= 200 && response.status < 300) {
- return response
- } else {
- let error = new Error(response.statusText);
- error.response = response;
- throw error
- }
- };
-
- const parseJson = response => response.json();
-
- export function YouTubeSearch(query) {
- const params = {
- part: 'snippet',
- type: 'video',
- key: KEY,
- q: query
- };
-
- return fetch(`${ENDPOINT}/search?${querystring.stringify(params)}`)
- .then(checkStatus)
- .then(parseJson);
- }
-
- export function YouTubeVideoInfo(id) {
- const params = {
- part: 'statistics,contentDetails',
- key: KEY,
- id: id
- };
-
- return fetch(`${ENDPOINT}/videos?${querystring.stringify(params)}`)
- .then(checkStatus)
- .then(parseJson);
- }
|