private void SetAccessToken(int customerId) { if (customerId != 0) { _brandPatnerId = customerId.ToString(); if (string.IsNullOrEmpty(_accessToken.Trim())) { BoxApiAuthenticationDto _boxApiAuthenticationDto = GetAPIToken(_brandPatnerId); _accessToken = string.Format("{0} {1}", _boxApiAuthenticationDto.token_type, _boxApiAuthenticationDto.access_token); } } }
private BoxApiAuthenticationDto GetAPIToken(string brandPatnerId) { string requestURL = string.Empty; string rawResponse = null; BoxApiAuthenticationDto _boxApiAuthenticationDto = new BoxApiAuthenticationDto(); try { HttpClientHandler handler = new HttpClientHandler(); using (_httpClient = new HttpClient(handler)) { _httpClient.BaseAddress = _apiBaseUri; _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); _httpClient.DefaultRequestHeaders.Add("Application-ID", _crmApplicationId); _httpClient.DefaultRequestHeaders.Add("Application-Key", _crmApplicationKey); _httpClient.DefaultRequestHeaders.Add("ExigoBrandPartnerId", _brandPatnerId); var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", _grantType) }); Dictionary <string, string> queryParameterBuilder = new Dictionary <string, string>(); queryParameterBuilder.Add("grant_type", _grantType); var result = _httpClient.PostAsync(_postTokenUrl, content).Result; if (result.IsSuccessStatusCode) { rawResponse = result.Content.ReadAsStringAsync().Result; _boxApiAuthenticationDto = result.Content.ReadAsAsync <BoxApiAuthenticationDto>().Result; } } } catch (Exception ex) { } return(_boxApiAuthenticationDto); }