Exemple #1
0
        private async void buttonConnection_Click(object sender, RoutedEventArgs e)
        {
            String pin = pinBox.Text;

            if (pin.Length > 0)
            {
                using (HttpClient client = new HttpClient())
                {
                    var values = new Dictionary <string, string>
                    {
                        { "client_id", "fb07d592bb27504" },
                        { "client_secret", "06eeb7e1337b1a5f699a670bf6fb24b14e4c57c6" },
                        { "grant_type", "pin" },
                        { "pin", pinBox.Text }
                    };
                    var content  = new FormUrlEncodedContent(values);
                    var response = await client.PostAsync("https://api.imgur.com/oauth2/token", content);

                    string ret = await response.Content.ReadAsStringAsync();

                    ImgurUWP_Imgur Imgur = JsonConvert.DeserializeObject <ImgurUWP_Imgur>(ret);
                    if (Imgur.account_id != 0)
                    {
                        this.Frame.Navigate(typeof(SecondPage), Imgur);
                    }
                    else
                    {
                        Imgur_Request request = JsonConvert.DeserializeObject <Imgur_Request>(ret);
                        infoBlock.Text = "Error : " + request.data.error;
                    }
                }
            }
            else
            {
                infoBlock.Text = "Error : Empty pin";
            }
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     Imgur          = e.Parameter as ImgurUWP_Imgur;
     textBlock.Text = "Connected as " + Imgur.account_username;
 }