Quickstart: Use the Bing Video Search JavaScript client library
Use this quickstart to begin searching for news with the Bing Video Search client library for JavaScript. While Bing Video Search has a REST API compatible with most programming languages, the client library provides an easy way to integrate the service into your applications. The source code for this sample can be found on GitHub. It contains more annotations and features.
Prerequisites
To set up a console application using the Bing Video Search client library:
- Run
npm install ms-rest-azure
in your development environment. - Run
npm install azure-cognitiveservices-videosearch
in your development environment.
Create and initialize the application
Create a new JavaScript file in your favorite IDE or editor, and add a
require()
statement for the Bing Video Search client library, andCognitiveServicesCredentials
module. Create a variable for your subscription key.const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials; const VideoSearchAPIClient = require('azure-cognitiveservices-videosearch');
Create an instance of
CognitiveServicesCredentials
with your key. Then use it to create an instance of the video search client.let credentials = new CognitiveServicesCredentials('YOUR-ACCESS-KEY'); let client = new VideoSearchAPIClient(credentials);
Send the search request
Use
client.videosOperations.search()
to send a search request to the Bing Video Search API. When the search results are returned, use.then()
to log the result.client.videosOperations.search('Interstellar Trailer').then((result) => { console.log(result.value); }).catch((err) => { throw err; });