public string GetGifs(string id) { string changedUrl = string.Format(URL, id); var httpWebRequest = (HttpWebRequest)WebRequest.Create(changedUrl); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "GET";//Можно GET httpWebRequest.Accept = "application/json"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.Headers.Add("api_key", "3qoY9i4HFXTbdsjOKQ9oHJ6PSWNOnSXM"); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { //ответ от сервера var result = streamReader.ReadToEnd(); //Десериализация GiphyModel rateModel = JsonConvert.DeserializeObject <GiphyModel>(result); return(rateModel.Data.Images.FixedHeightDownsampled.url.ToString()); } }
public static GiphyDto[] ToDtosArray(this GiphyModel model) { var list = new List <GiphyDto>(); foreach (var item in model.data) { list.Add(new GiphyDto() { Slug = item.slug, Url = item.images.preview_gif.url ?? item.images.original.url, Height = int.Parse(item.images.preview_gif.height ?? item.images.original.height), Width = int.Parse(item.images.preview_gif.width ?? item.images.original.width) }); } return(list.ToArray()); }
private void GetGifs(string q) { Device.BeginInvokeOnMainThread(async() => { GiphyModel gif = new GiphyModel(); var giphyGif = await http.getData <GiphyModel>("https://api.giphy.com/v1/gifs/search?api_key=JjHQg0Jx2beliftpj9GqeGEA3Ff8NsOa&q=" + q + "+weather&limit=" + rand.Next(1, 9)); foreach (var item in giphyGif.Data) { image_url = item.Images.Original.Url.AbsoluteUri; } if (giphyGif != null) { imgVWR.Source = image_url; } else { await DisplayAlert("Error", "null", "null"); } }); }