コード例 #1
0
 private void myGallery_Click(object sender, RoutedEventArgs e)
 {
     if (state == 2)
     {
         return;
     }
     ComboBox1.Visibility = Visibility.Collapsed;
     GridView1.Items.Clear();
     images = null;
     state  = 2;
     getImgurGallery();
 }
コード例 #2
0
 private void home_Click(object sender, RoutedEventArgs e)
 {
     if (state == 0)
     {
         return;
     }
     ComboBox1.Visibility = Visibility.Visible;
     GridView1.Items.Clear();
     images = null;
     state  = 0;
     getImgurGallery();
 }
コード例 #3
0
        private async void getImgurGallery()
        {
            try
            {
                HttpClient httpClient = new HttpClient();

                if (token.accessToken == null)
                {
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Client-ID", clientId);
                }
                else
                {
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.accessToken);
                }
                Uri requestUri;
                if (state == 0)
                {
                    requestUri = new Uri("https://api.imgur.com/3/gallery/hot/" + box + "/month/0");
                }
                else if (state == 1)
                {
                    requestUri = new Uri("https://api.imgur.com/3/account/me/favorites/0/newest");
                }
                else
                {
                    requestUri = new Uri("https://api.imgur.com/3/account/me/images");
                }
                Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();

                HttpResponseMessage response = await httpClient.GetAsync(requestUri);

                Debug.WriteLine(response);
                string jsonResponse = await response.Content.ReadAsStringAsync();

                images = JsonConvert.DeserializeObject <ImgurImages>(jsonResponse);
                foreach (var tmp in images.images)
                {
                    GridView1.Items.Add(tmp);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
        }
コード例 #4
0
        private void changedBox_Click(object sender, object e)
        {
            var comboBoxItem = ComboBox1.SelectedItem as ComboBoxItem;

            if (comboBoxItem == null)
            {
                return;
            }
            string content = comboBoxItem.Content as string;

            if (content.Length > 0 && content.Equals(box) == false)
            {
                box = content;
                GridView1.Items.Clear();
                images = null;
                getImgurGallery();
            }
        }
コード例 #5
0
        private void webView_LoadCompleted(object sender, NavigationEventArgs e)
        {
            WebView tmp = sender as WebView;

            string myUrl = tmp.Source.ToString();

            if (myUrl.IndexOf("https://api.imgur.com/oauth2/authorize/") == -1)
            {
                myWeb.Visibility = Visibility.Collapsed;
            }
            else
            {
                myWeb.Visibility = Visibility.Visible;
            }
            try
            {
                if (myUrl.IndexOf("access_token=") == -1)
                {
                    throw new Exception("no access token");
                }
                myUrl             = myUrl.Substring(myUrl.IndexOf("access_token=") + 13);
                token.accessToken = myUrl.Substring(0, myUrl.IndexOf("&"));
                if (myUrl.IndexOf("refresh_token=") == -1)
                {
                    throw new Exception("no access token");
                }
                myUrl = myUrl.Substring(myUrl.IndexOf("refresh_token=") + 14);
                token.refreshToken = myUrl.Substring(0, myUrl.IndexOf("&"));
                myWeb.Visibility   = Visibility.Collapsed;
                Serialize();
                GridView1.Items.Clear();
                images = null;
                getImgurGallery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Couldn't set tokens");
            }
        }