public async Task <AdvancedTweet> GetTweet(string id) { var client = new OAuthClient(accessToken); AdvancedTweet tweet; HttpResponseMessage res = new HttpResponseMessage(); try { res = await client.GetAsync("https://api.twitter.com/1.1/statuses/show.json?id=" + id); tweet = MyJsonConverter.DeserializeStreamTweet(res.Content.ToString(), accessToken); return(tweet); } catch (Exception ex) { try { var errors = JsonConvert.DeserializeObject <Errors>(res.Content.ToString()); var error = errors.errors[0]; throw new Exception("Error " + error.code + ":" + error.message); } catch (Exception) { throw new Exception("ツイートの取得に失敗しました。", ex); } } }
public async Task GetStream(Action <AdvancedTweet> fetchAction) { OAuthClient client = new OAuthClient(accessToken); await client.GetStreamAsync("https://userstream.twitter.com/1.1/user.json", (json) => { AdvancedTweet advancedTweet; try { advancedTweet = MyJsonConverter.DeserializeStreamTweet(json, accessToken); } catch (Exception ex) { throw new Exception("また知らない形のjsonが投げられたみたい。:" + json, ex); } fetchAction(advancedTweet); }); }