Quickstart: Perform a video search with the Bing Video Search SDK for C#

Use this quickstart to begin searching for news with the Bing Video Search SDK for C#. While Bing Video Search has a REST API compatible with most programming languages, the SDK provides an easy way to integrate the service into your applications. The source code for this sample can be found on GitHub with additional annotations, and features.


To add the Bing Video Search SDK to your project, select Manage NuGet Packages from Solution Explorer in Visual Studio. Add the Microsoft.Azure.CognitiveServices.Search.VideoSearch package.

Installing the [NuGet Video Search SDK package] also installs the following dependencies:

  • Microsoft.Rest.ClientRuntime
  • Microsoft.Rest.ClientRuntime.Azure
  • Newtonsoft.Json

You must have a Cognitive Services API account with access to the Bing Search APIs. If you don't have an Azure subscription, you can create an account for free. Before continuing, You will need the access key provided after activating your free trial, or a paid subscription key from your Azure dashboard.

Create and initialize a project

  1. Create a new C# console solution in Visual Studio. Then add the following into the main code file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Azure.CognitiveServices.Search.VideoSearch;
    using Microsoft.Azure.CognitiveServices.Search.VideoSearch.Models;
  2. Instantiate the client by creating a new ApiKeyServiceClientCredentials object with your subscription key, and calling the constructor.

    var client = new VideoSearchAPI(new ApiKeyServiceClientCredentials("YOUR-ACCESS-KEY"));

Send a search request and process the results

  1. Use the client to send a search request. Use "SwiftKey" for the search query.

    var videoResults = client.Videos.SearchAsync(query: "SwiftKey").Result;
  2. If any results were returned, get the first one with videoResults.Value[0]. Then print the video's ID, title, and url.

    if (videoResults.Value.Count > 0)
        var firstVideoResult = videoResults.Value[0];
        Console.WriteLine($"\r\nVideo result count: {videoResults.Value.Count}");
        Console.WriteLine($"First video id: {firstVideoResult.VideoId}");
        Console.WriteLine($"First video name: {firstVideoResult.Name}");
        Console.WriteLine($"First video url: {firstVideoResult.ContentUrl}");
        Console.WriteLine("Couldn't find video results!");

Next steps

See also