-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
executable file
·65 lines (59 loc) · 2.34 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace EPicture
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void tokenButton_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("https://api.imgur.com/oauth2/authorize?client_id=8e0148d95c9866b&response_type=pin"));
}
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", "8e0148d95c9866b" },
{ "client_secret", "46eba94c9f31b5b053a9f2aa2cb289845a454b7e" },
{ "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();
EPicture_Imgur epi = JsonConvert.DeserializeObject<EPicture_Imgur>(ret);
if (epi.account_id != 0) {
this.Frame.Navigate(typeof(SecondPage), epi);
} else {
Imgur_Request request = JsonConvert.DeserializeObject<Imgur_Request>(ret);
infoBlock.Text = "Error : " + request.data.error;
}
}
} else {
infoBlock.Text = "Error : Empty pin";
}
}
private void pinBox_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (pinBox.Text.CompareTo("PIN code") == 0)
{
pinBox.Text = "";
}
}
private void pinBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
}
}