Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private async Task<ActionResult> RunQueryVideoAsync(SearchDataVideo model)
{
// Retrieving the access token from the service
string accessToken = await GetVideoIndexerAccessToken();
// Setting up HTTP client request
HttpClient _httpClientSearchVideos = new HttpClient();
// Pulling off video indexer API information
_builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
_configuration = _builder.Build();
string uriSearchVideos = _configuration["UriSearchVideos"];
string ocpApimSubscriptionKey = _configuration["OcpApimSubscriptionKey"];
// Setting up request headers
_httpClientSearchVideos.DefaultRequestHeaders.Add("x-ms-client-request-id", "");
_httpClientSearchVideos.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ocpApimSubscriptionKey);
// Request parameters
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["query"] = model.searchText;
queryString["language"] = "pt-BR";
queryString["pageSize"] = "25";
queryString["skip"] = "0";
queryString["accessToken"] = accessToken;
try
{
var response = await _httpClientSearchVideos.GetAsync(uriSearchVideos + queryString);
var result = JsonConvert.DeserializeObject<RootVideo>(await response.Content.ReadAsStringAsync());
model.resultVideos = result.results;
return View(model);
}
catch (Exception e)
{
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment