Created
March 10, 2020 15:23
-
-
Save fabriciosanchez/ad089bc45309e7215c572d152a018172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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