コード例 #1
0
ファイル: Model.cs プロジェクト: Kuro4/QiitaStocksViewer
            private async void getStockInfo()
            {
                Uri    uri    = new Uri("https://qiita.com/api/v2/items/" + _PostID + "/stockers");
                var    result = await new HttpClient().GetStringAsync(uri);
                JArray data   = (JArray)JsonConvert.DeserializeObject(result);

                foreach (JObject item in data)
                {
                    _StockCount.Value++;
                    _StockedPerson.Add(item[JsonKeysEx.getKeyName(JsonKeys.e_id)].ToString());
                }
            }
コード例 #2
0
ファイル: Model.cs プロジェクト: Kuro4/QiitaStocksViewer
        public async void LoadFromQiita()
        {
            if (!string.IsNullOrWhiteSpace(_UserID.Value))
            {
                var    client = new HttpClient();
                Uri    uri    = new Uri("https://qiita.com/api/v2/users/" + _UserID.Value + "/items");
                string result;
                try
                {
                    if (string.IsNullOrWhiteSpace(_AccessToken))
                    {
                        result = await client.GetStringAsync(uri);
                    }
                    else
                    {
                        var request = new HttpRequestMessage();
                        request.Method                = HttpMethod.Get;
                        request.RequestUri            = uri;
                        request.Headers.Host          = "qiita.com";
                        request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _AccessToken);
                        var respons = await client.SendAsync(request);

                        result = await respons.Content.ReadAsStringAsync();
                    }
                    JArray data = (JArray)JsonConvert.DeserializeObject(result);
                    _PostList.Clear();
                    foreach (JObject item in data)
                    {
                        _PostList.Add(new PostInformation()
                        {
                            _Title         = item[JsonKeysEx.getKeyName(JsonKeys.e_title)].ToString(),
                            _PostTime      = ISO8601ToDateTime(item[JsonKeysEx.getKeyName(JsonKeys.e_created_at)].ToString()),
                            _UpDatedTime   = ISO8601ToDateTime(item[JsonKeysEx.getKeyName(JsonKeys.e_updated_at)].ToString()),
                            _LimitedShared = bool.Parse(item[JsonKeysEx.getKeyName(JsonKeys.e_private)].ToString()),
                            _URL           = new Uri(item[JsonKeysEx.getKeyName(JsonKeys.e_url)].ToString()),
                            _StockInfo     = new PostInformation.StockInformation(item[JsonKeysEx.getKeyName(JsonKeys.e_id)].ToString()),
                        });
                    }
                }
                catch (HttpRequestException e)
                {
                    MessageBox.Show("エラーが発生しました" + Environment.NewLine
                                    + "ユーザーID,AccessTokenが間違っているか、リクエスト制限を超えた可能性があります"   + Environment.NewLine
                                    + "(リクエスト回数はIPアドレス毎に \n 認証無:60回/h \n 認証有:1000回/h \n までです)", e.GetType().ToString());
                }
            }
        }