/// <summary> /// Search for video only. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnVideosSearch_Click(object sender, EventArgs e) { Repeater rptResult = new Repeater(); string query = tbQueryString.Text; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var mediaQuery = bingContainer.Video(query, null, market, null, null, null, null, null); mediaQuery = mediaQuery.AddQueryOption("$top", 50); // Run the query and display the results. var mediaResults = mediaQuery.Execute(); Label lblResults = new Label(); StringBuilder searchResult = new StringBuilder(); foreach (Bing.VideoResult vResult in mediaResults) { searchResult.Append(string.Format("Video Tile: <a href={1}>{0}</a><br />Video URL: {1}<br />", vResult.Title, vResult.MediaUrl)); } lblResults.Text = searchResult.ToString(); Panel1.Controls.Add(lblResults); }
/// <summary> /// Documentation under IChronozoomSVC /// </summary> BaseJsonResult <IEnumerable <Bing.VideoResult> > IBingSearchAPI.GetVideos(string query, string top, string skip) { return(ApiOperation <BaseJsonResult <IEnumerable <Bing.VideoResult> > >(delegate(User user, Storage storage) { var searchResults = new List <Bing.VideoResult>(); if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"])) { BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]; } #if RELEASE if (user == null) { // Setting status code to 403 to prevent redirection to authentication resource if status code is 401. SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser); return new BaseJsonResult <IEnumerable <Bing.VideoResult> >(searchResults); } #endif int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit; int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset; try { var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl)); bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey); var videoQuery = bingContainer.Video(query, null, null, null, null, null, null, null); videoQuery = videoQuery.AddQueryOption("$top", resultsCount); videoQuery = videoQuery.AddQueryOption("$skip", offset); var videoResults = videoQuery.Execute(); foreach (var result in videoResults) { searchResults.Add(result); } } catch (ArgumentNullException) { SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery); } catch (Exception ex) { SetStatusCode(HttpStatusCode.InternalServerError, ex.Message); } return new BaseJsonResult <IEnumerable <Bing.VideoResult> >(searchResults); })); }
/// <summary> /// Documentation under IChronozoomSVC /// </summary> BaseJsonResult<IEnumerable<Bing.VideoResult>> IBingSearchAPI.GetVideos(string query, string top, string skip) { return ApiOperation<BaseJsonResult<IEnumerable<Bing.VideoResult>>>(delegate(User user, Storage storage) { var searchResults = new List<Bing.VideoResult>(); if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"])) { BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]; } #if RELEASE if (user == null) { // Setting status code to 403 to prevent redirection to authentication resource if status code is 401. SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser); return new BaseJsonResult<IEnumerable<Bing.VideoResult>>(searchResults); } #endif int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit; int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset; try { var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl)); bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey); var videoQuery = bingContainer.Video(query, null, null, null, null, null, null, null); videoQuery = videoQuery.AddQueryOption("$top", resultsCount); videoQuery = videoQuery.AddQueryOption("$skip", offset); var videoResults = videoQuery.Execute(); foreach (var result in videoResults) { searchResults.Add(result); } } catch (ArgumentNullException) { SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery); } catch (Exception ex) { SetStatusCode(HttpStatusCode.InternalServerError, ex.Message); } return new BaseJsonResult<IEnumerable<Bing.VideoResult>>(searchResults); }); }