buddy

node MVC discord bot
Log | Files | Refs | README

README.md (2854B)


      1 # youtube-api-v3-search
      2 
      3 [![Build Status](https://travis-ci.org/LionRoar/youtube-api-v3-search.svg?branch=master)](https://travis-ci.org/LionRoar/youtube-api-v3-search)
      4 
      5 ## YouTube Search Google API for [Node.js](https://nodejs.org/en) and Browser
      6 
      7 ### Search for YouTube videos, channels, playlists and live events via Google API
      8 
      9 * [Node.js](https://nodejs.org/en) using [https](https://nodejs.org/api/https.html) and in the Browser using [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)
     10 
     11 * <del>Super light no third-party libraries</del> **Added** [browser-resolve](https://www.npmjs.com/package/browser-resolve) for performance.
     12 * Supports the [Prmise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
     13 
     14 * Thanks to @MaximVanhove for adding Support for CommonJS, AMD and global variable.
     15 
     16 -----------------
     17 
     18 Installing
     19 
     20 ==========
     21 
     22 Using npm:
     23 
     24 ``` bash
     25  npm install youtube-api-v3-search
     26 ```
     27 
     28 Using cdn:
     29 
     30 ```html
     31 
     32 
     33  <script src="https://unpkg.com/youtube-api-v3-search@1.2.1/dist/youtube-api-v3-search.min.js"></script>
     34 
     35 
     36  ```
     37 
     38 -----------------
     39 
     40 Example Usage
     41 
     42 =============
     43 
     44 ```js
     45 
     46 const searchYoutube = require('youtube-api-v3-search');
     47 ```
     48 
     49 or
     50 
     51 ```js
     52 import searchYoutube from 'youtube-api-v3-search';
     53 
     54 ```
     55 
     56 -----------------
     57 
     58 ## Callbacks
     59 
     60 ```js
     61 
     62 /**
     63  * Searching YouTube.
     64  * @param {string} $YOUTUBE_KEY youtube api-key
     65  * @param {Object} $options search parameters.
     66  * @param {function} callback( @param error , @param result).  
     67  * @return {void}
     68  */
     69 
     70 searchYoutube($YOUTUBE_KEY,$options,callback);
     71 ```
     72 
     73 -----------------
     74 
     75 ## Promises __Just don't callback and you'll get a Promise :)__
     76 
     77 ```js
     78 
     79 // NOT passing callback as the 3rd argument it returns Promise
     80 /**
     81  * Searching YouTube.
     82  * @param {string} $YOUTUBE_KEY youtube api-key
     83  * @param {Object} $options search parameters.
     84  * @return {Promise} The result of the search .
     85  */
     86 
     87 searchYoutube($YOUTUBE_KEY,$options);
     88 ```
     89 
     90 ## Async/Await
     91 
     92 ```js
     93 async () => {
     94   let result = await searchYoutube($YOUTUBE_KEY,options);
     95 }
     96 ```
     97 
     98 -----------------
     99 
    100 ## Options
    101 
    102 ### [options/parameters]
    103 
    104 ### **Search Options**
    105 
    106 _The **q** parameter specifies the query term to search for._
    107 
    108 _The **part** parameter specifies a comma-separated list of one or more search resource properties that the API response will include. Set the parameter value to snippet._
    109 
    110 _The **type** parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. The default value is video,channel,playlist._
    111 
    112 _Acceptable values are:_
    113 
    114 * _channel_
    115 * _playlist_
    116 * _video_
    117 
    118 #### Example
    119 
    120 ```js
    121 
    122 const options = {
    123   q:'nodejs',
    124   part:'snippet',
    125   type:'video'
    126 }
    127 ```
    128 
    129 #### [YouTube API Reference Search#parameters](https://developers.google.com/youtube/v3/docs/search/list#parameters)