1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 using System.Collections.Generic;
36 public class HttpTwitter : ICloneable
40 ///OAuthのアクセストークン取得先URI
42 private const string AccessTokenUrlXAuth = "https://api.twitter.com/oauth/access_token";
43 private const string RequestTokenUrl = "https://api.twitter.com/oauth/request_token";
44 private const string AuthorizeUrl = "https://api.twitter.com/oauth/authorize";
45 private const string AccessTokenUrl = "https://api.twitter.com/oauth/access_token";
47 private const string PostMethod = "POST";
48 private const string GetMethod = "GET";
50 private IHttpConnection httpCon; //HttpConnectionApi or HttpConnectionOAuth
51 private HttpVarious httpConVar = new HttpVarious();
53 private enum AuthMethod
58 private AuthMethod connectionType = AuthMethod.Basic;
60 private string requestToken;
62 private static string tk = "";
63 private static string tks = "";
64 private static string un = "";
66 public void Initialize(string accessToken,
67 string accessTokenSecret,
72 HttpOAuthApiProxy con = new HttpOAuthApiProxy();
73 if (tk != accessToken || tks != accessTokenSecret ||
74 un != username || connectionType != AuthMethod.OAuth)
76 // 以前の認証状態よりひとつでも変化があったらhttpヘッダより読み取ったカウントは初期化
78 tks = accessTokenSecret;
81 con.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret, accessToken, accessTokenSecret, username, userId, "screen_name", "user_id");
83 connectionType = AuthMethod.OAuth;
87 public string AccessToken
92 return ((HttpConnectionOAuth)httpCon).AccessToken;
98 public string AccessTokenSecret
103 return ((HttpConnectionOAuth)httpCon).AccessTokenSecret;
109 public string AuthenticatedUsername
114 return httpCon.AuthUsername;
120 public long AuthenticatedUserId
125 return httpCon.AuthUserId;
132 httpCon.AuthUserId = value;
136 public string Password
144 public bool AuthGetRequestToken(ref string content)
147 bool result = ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlowRequest(RequestTokenUrl, AuthorizeUrl, ref requestToken, ref authUri);
148 content = authUri.ToString();
152 public HttpStatusCode AuthGetAccessToken(string pin)
154 return ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlow(AccessTokenUrl, requestToken, pin);
157 public HttpStatusCode AuthUserAndPass(string username, string password, ref string content)
159 return httpCon.Authenticate(new Uri(AccessTokenUrlXAuth), username, password, ref content);
162 public void ClearAuthInfo()
164 this.Initialize("", "", "", 0);
167 public HttpStatusCode UpdateStatus(string status, long? replyToId, ref string content)
169 Dictionary<string, string> param = new Dictionary<string, string>();
170 param.Add("status", status);
171 if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
172 param.Add("include_entities", "true");
173 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
175 return httpCon.GetContent(PostMethod,
176 this.CreateTwitterUri("/1.1/statuses/update.json"),
183 public HttpStatusCode UpdateStatusWithMedia(string status, long? replyToId, FileInfo mediaFile, ref string content)
186 Dictionary<string, string> param = new Dictionary<string, string>();
187 param.Add("status", status);
188 if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
189 param.Add("include_entities", "true");
190 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
192 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
193 binary.Add(new KeyValuePair<string, FileInfo>("media[]", mediaFile));
195 return httpCon.GetContent(PostMethod,
196 this.CreateTwitterUri("/1.1/statuses/update_with_media.json"),
200 this.CreateRatelimitHeadersDict(),
201 this.CreateApiCalllback("/statuses/update_with_media"));
204 public HttpStatusCode DestroyStatus(long id)
206 string content = null;
208 return httpCon.GetContent(PostMethod,
209 this.CreateTwitterUri("/1.1/statuses/destroy/" + id + ".json"),
216 public HttpStatusCode SendDirectMessage(string status, string sendto, ref string content)
218 Dictionary<string, string> param = new Dictionary<string, string>();
219 param.Add("text", status);
220 param.Add("screen_name", sendto);
221 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
223 return httpCon.GetContent(PostMethod,
224 this.CreateTwitterUri("/1.1/direct_messages/new.json"),
231 public HttpStatusCode DestroyDirectMessage(long id)
233 string content = null;
235 var param = new Dictionary<string, string>();
236 param.Add("id", id.ToString());
238 return httpCon.GetContent(PostMethod,
239 this.CreateTwitterUri("/1.1/direct_messages/destroy.json"),
246 public HttpStatusCode RetweetStatus(long id, ref string content)
248 Dictionary<string, string> param = new Dictionary<string, string>();
249 param.Add("include_entities", "true");
251 return httpCon.GetContent(PostMethod,
252 this.CreateTwitterUri("/1.1/statuses/retweet/" + id + ".json"),
259 public HttpStatusCode ShowUserInfo(string screenName, ref string content)
261 Dictionary<string, string> param = new Dictionary<string, string>();
262 param.Add("screen_name", screenName);
263 param.Add("include_entities", "true");
264 return httpCon.GetContent(GetMethod,
265 this.CreateTwitterUri("/1.1/users/show.json"),
268 this.CreateRatelimitHeadersDict(),
269 this.CreateApiCalllback("/users/show/:id"));
272 public HttpStatusCode CreateFriendships(string screenName, ref string content)
274 Dictionary<string, string> param = new Dictionary<string, string>();
275 param.Add("screen_name", screenName);
277 return httpCon.GetContent(PostMethod,
278 this.CreateTwitterUri("/1.1/friendships/create.json"),
285 public HttpStatusCode DestroyFriendships(string screenName, ref string content)
287 Dictionary<string, string> param = new Dictionary<string, string>();
288 param.Add("screen_name", screenName);
290 return httpCon.GetContent(PostMethod,
291 this.CreateTwitterUri("/1.1/friendships/destroy.json"),
298 public HttpStatusCode CreateBlock(string screenName, ref string content)
300 Dictionary<string, string> param = new Dictionary<string, string>();
301 param.Add("screen_name", screenName);
303 return httpCon.GetContent(PostMethod,
304 this.CreateTwitterUri("/1.1/blocks/create.json"),
311 public HttpStatusCode DestroyBlock(string screenName, ref string content)
313 Dictionary<string, string> param = new Dictionary<string, string>();
314 param.Add("screen_name", screenName);
316 return httpCon.GetContent(PostMethod,
317 this.CreateTwitterUri("/1.1/blocks/destroy.json"),
324 public HttpStatusCode ReportSpam(string screenName, ref string content)
326 Dictionary<string, string> param = new Dictionary<string, string>();
327 param.Add("screen_name", screenName);
329 return httpCon.GetContent(PostMethod,
330 this.CreateTwitterUri("/1.1/users/report_spam.json"),
337 public HttpStatusCode ShowFriendships(string souceScreenName, string targetScreenName, ref string content)
339 Dictionary<string, string> param = new Dictionary<string, string>();
340 param.Add("source_screen_name", souceScreenName);
341 param.Add("target_screen_name", targetScreenName);
343 return httpCon.GetContent(GetMethod,
344 this.CreateTwitterUri("/1.1/friendships/show.json"),
347 this.CreateRatelimitHeadersDict(),
348 this.CreateApiCalllback("/friendships/show"));
351 public HttpStatusCode ShowStatuses(long id, ref string content)
353 Dictionary<string, string> param = new Dictionary<string, string>();
354 param.Add("include_entities", "true");
355 return httpCon.GetContent(GetMethod,
356 this.CreateTwitterUri("/1.1/statuses/show/" + id + ".json"),
359 this.CreateRatelimitHeadersDict(),
360 this.CreateApiCalllback("/statuses/show/:id"));
363 public HttpStatusCode CreateFavorites(long id, ref string content)
365 var param = new Dictionary<string, string>();
366 param.Add("id", id.ToString());
368 return httpCon.GetContent(PostMethod,
369 this.CreateTwitterUri("/1.1/favorites/create.json"),
376 public HttpStatusCode DestroyFavorites(long id, ref string content)
378 var param = new Dictionary<string, string>();
379 param.Add("id", id.ToString());
381 return httpCon.GetContent(PostMethod,
382 this.CreateTwitterUri("/1.1/favorites/destroy.json"),
389 public HttpStatusCode HomeTimeline(int? count, long? max_id, long? since_id, ref string content)
391 Dictionary<string, string> param = new Dictionary<string, string>();
393 param.Add("count", count.ToString());
395 param.Add("max_id", max_id.ToString());
396 if (since_id != null)
397 param.Add("since_id", since_id.ToString());
399 param.Add("include_entities", "true");
401 return httpCon.GetContent(GetMethod,
402 this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
405 this.CreateRatelimitHeadersDict(),
406 this.CreateApiCalllback("/statuses/home_timeline"));
409 public HttpStatusCode UserTimeline(long? user_id, string screen_name, int? count, long? max_id, long? since_id, ref string content)
411 Dictionary<string, string> param = new Dictionary<string, string>();
413 if ((user_id == null && string.IsNullOrEmpty(screen_name)) ||
414 (user_id != null && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
417 param.Add("user_id", user_id.ToString());
418 if (!string.IsNullOrEmpty(screen_name))
419 param.Add("screen_name", screen_name);
421 param.Add("count", count.ToString());
423 param.Add("max_id", max_id.ToString());
424 if (since_id != null)
425 param.Add("since_id", since_id.ToString());
427 param.Add("include_rts", "true");
428 param.Add("include_entities", "true");
430 return httpCon.GetContent(GetMethod,
431 this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
434 this.CreateRatelimitHeadersDict(),
435 this.CreateApiCalllback("/statuses/user_timeline"));
438 public HttpStatusCode Mentions(int? count, long? max_id, long? since_id, ref string content)
440 Dictionary<string, string> param = new Dictionary<string, string>();
442 param.Add("count", count.ToString());
444 param.Add("max_id", max_id.ToString());
445 if (since_id != null)
446 param.Add("since_id", since_id.ToString());
448 param.Add("include_entities", "true");
450 return httpCon.GetContent(GetMethod,
451 this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
454 this.CreateRatelimitHeadersDict(),
455 this.CreateApiCalllback("/statuses/mentions_timeline"));
458 public HttpStatusCode DirectMessages(int? count, long? max_id, long? since_id, ref string content)
460 Dictionary<string, string> param = new Dictionary<string, string>();
462 param.Add("count", count.ToString());
464 param.Add("max_id", max_id.ToString());
465 if (since_id != null)
466 param.Add("since_id", since_id.ToString());
467 param.Add("include_entities", "true");
469 return httpCon.GetContent(GetMethod,
470 this.CreateTwitterUri("/1.1/direct_messages.json"),
473 this.CreateRatelimitHeadersDict(),
474 this.CreateApiCalllback("/direct_messages"));
477 public HttpStatusCode DirectMessagesSent(int? count, long? max_id, long? since_id, ref string content)
479 Dictionary<string, string> param = new Dictionary<string, string>();
481 param.Add("count", count.ToString());
483 param.Add("max_id", max_id.ToString());
484 if (since_id != null)
485 param.Add("since_id", since_id.ToString());
486 param.Add("include_entities", "true");
488 return httpCon.GetContent(GetMethod,
489 this.CreateTwitterUri("/1.1/direct_messages/sent.json"),
492 this.CreateRatelimitHeadersDict(),
493 this.CreateApiCalllback("/direct_messages/sent"));
496 public HttpStatusCode Favorites(int? count, int? page, ref string content)
498 Dictionary<string, string> param = new Dictionary<string, string>();
499 if (count != null) param.Add("count", count.ToString());
503 param.Add("page", page.ToString());
506 param.Add("include_entities", "true");
508 return httpCon.GetContent(GetMethod,
509 this.CreateTwitterUri("/1.1/favorites/list.json"),
512 this.CreateRatelimitHeadersDict(),
513 this.CreateApiCalllback("/favorites/list"));
516 public HttpStatusCode Search(string words, string lang, int? count, long? maxId, long? sinceId, ref string content)
518 Dictionary<string, string> param = new Dictionary<string, string>();
519 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
520 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
521 if (count != null) param.Add("count", count.ToString());
522 if (maxId != null) param.Add("max_id", maxId.ToString());
523 if (sinceId != null) param.Add("since_id", sinceId.ToString());
525 if (param.Count == 0) return HttpStatusCode.BadRequest;
527 param.Add("result_type", "recent");
528 param.Add("include_entities", "true");
529 return httpCon.GetContent(GetMethod,
530 this.CreateTwitterUri("/1.1/search/tweets.json"),
533 this.CreateRatelimitHeadersDict(),
534 this.CreateApiCalllback("/search/tweets"));
537 public HttpStatusCode SavedSearches(ref string content)
539 return httpCon.GetContent(GetMethod,
540 this.CreateTwitterUri("/1.1/saved_searches/list.json"),
543 this.CreateRatelimitHeadersDict(),
544 this.CreateApiCalllback("/saved_searches/list"));
547 public HttpStatusCode FollowerIds(long cursor, ref string content)
549 Dictionary<string, string> param = new Dictionary<string, string>();
550 param.Add("cursor", cursor.ToString());
552 return httpCon.GetContent(GetMethod,
553 this.CreateTwitterUri("/1.1/followers/ids.json"),
556 this.CreateRatelimitHeadersDict(),
557 this.CreateApiCalllback("/followers/ids"));
560 public HttpStatusCode NoRetweetIds(ref string content)
562 return httpCon.GetContent(GetMethod,
563 this.CreateTwitterUri("/1.1/friendships/no_retweets/ids.json"),
566 this.CreateRatelimitHeadersDict(),
567 this.CreateApiCalllback("/friendships/no_retweets/ids"));
570 public HttpStatusCode RateLimitStatus(ref string content)
572 return httpCon.GetContent(GetMethod,
573 this.CreateTwitterUri("/1.1/application/rate_limit_status.json"),
576 this.CreateRatelimitHeadersDict(),
577 this.CreateApiCalllback("/application/rate_limit_status"));
581 public HttpStatusCode GetLists(string user, ref string content)
583 Dictionary<string, string> param = new Dictionary<string, string>();
584 param.Add("screen_name", user);
586 return httpCon.GetContent(GetMethod,
587 this.CreateTwitterUri("/1.1/lists/list.json"),
590 this.CreateRatelimitHeadersDict(),
591 this.CreateApiCalllback("/lists/list"));
594 public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
596 string mode = "public";
600 Dictionary<string, string> param = new Dictionary<string, string>();
601 param.Add("screen_name", user);
602 param.Add("list_id", list_id);
603 if (name != null) param.Add("name", name);
604 if (mode != null) param.Add("mode", mode);
605 if (description != null) param.Add("description", description);
607 return httpCon.GetContent(PostMethod,
608 this.CreateTwitterUri("/1.1/lists/update.json"),
615 public HttpStatusCode DeleteListID(string user, string list_id, ref string content)
617 Dictionary<string, string> param = new Dictionary<string, string>();
618 param.Add("screen_name", user);
619 param.Add("list_id", list_id);
621 return httpCon.GetContent(PostMethod,
622 this.CreateTwitterUri("/1.1/lists/destroy.json"),
629 public HttpStatusCode GetListsSubscriptions(string user, ref string content)
631 Dictionary<string, string> param = new Dictionary<string, string>();
632 param.Add("screen_name", user);
634 return httpCon.GetContent(GetMethod,
635 this.CreateTwitterUri("/1.1/lists/subscriptions.json"),
638 this.CreateRatelimitHeadersDict(),
639 this.CreateApiCalllback("/lists/subscriptions"));
642 public HttpStatusCode GetListsStatuses(long userId, long list_id, int? per_page, long? max_id, long? since_id, Boolean isRTinclude, ref string content)
644 //認証なくても取得できるが、protectedユーザー分が抜ける
645 Dictionary<string, string> param = new Dictionary<string, string>();
646 param.Add("user_id", userId.ToString());
647 param.Add("list_id", list_id.ToString());
648 param.Add("include_rts", isRTinclude ? "true" : "false");
649 if (per_page != null)
650 param.Add("count", per_page.ToString());
652 param.Add("max_id", max_id.ToString());
653 if (since_id != null)
654 param.Add("since_id", since_id.ToString());
655 param.Add("include_entities", "true");
657 return httpCon.GetContent(GetMethod,
658 this.CreateTwitterUri("/1.1/lists/statuses.json"),
661 this.CreateRatelimitHeadersDict(),
662 this.CreateApiCalllback("/lists/statuses"));
665 public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
667 string mode = "public";
671 Dictionary<string, string> param = new Dictionary<string, string>();
672 param.Add("name", listname);
673 param.Add("mode", mode);
674 if (!string.IsNullOrEmpty(description))
675 param.Add("description", description);
677 return httpCon.GetContent(PostMethod,
678 this.CreateTwitterUri("/1.1/lists/create.json"),
685 public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
687 Dictionary<string, string> param = new Dictionary<string, string>();
688 param.Add("screen_name", user);
689 param.Add("list_id", list_id);
690 param.Add("cursor", cursor.ToString());
691 return httpCon.GetContent(GetMethod,
692 this.CreateTwitterUri("/1.1/lists/members.json"),
695 this.CreateRatelimitHeadersDict(),
696 this.CreateApiCalllback("/lists/members"));
699 public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
701 Dictionary<string, string> param = new Dictionary<string, string>();
702 param.Add("list_id", list_id);
703 param.Add("screen_name", memberName);
704 return httpCon.GetContent(PostMethod,
705 this.CreateTwitterUri("/1.1/lists/members/create.json"),
712 public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content)
714 Dictionary<string, string> param = new Dictionary<string, string>();
715 param.Add("screen_name", memberName);
716 param.Add("list_id", list_id);
717 return httpCon.GetContent(PostMethod,
718 this.CreateTwitterUri("/1.1/lists/members/destroy.json"),
725 public HttpStatusCode ShowListMember(string list_id, string memberName, ref string content)
727 Dictionary<string, string> param = new Dictionary<string, string>();
728 param.Add("screen_name", memberName);
729 param.Add("list_id", list_id);
730 return httpCon.GetContent(GetMethod,
731 this.CreateTwitterUri("/1.1/lists/members/show.json"),
734 this.CreateRatelimitHeadersDict(),
735 this.CreateApiCalllback("/lists/members/show"));
739 public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int? count, int? page, ref string content)
741 Dictionary<string, string> param = new Dictionary<string, string>();
743 param.Add("count", count.ToString());
745 param.Add("page", page.ToString());
747 param.Add("id", statusid.ToString());
749 return httpCon.GetContent(GetMethod,
750 this.CreateTwitterUri("/1.1/statuses/retweeters/ids.json"),
753 this.CreateRatelimitHeadersDict(),
754 this.CreateApiCalllback("/statuses/retweeters/ids"));
757 public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content)
759 Dictionary<string, string> param = new Dictionary<string, string>();
761 param.Add("name", WebUtility.HtmlEncode(name));
762 param.Add("url", url);
763 param.Add("location", WebUtility.HtmlEncode(location));
764 param.Add("description", WebUtility.HtmlEncode(description));
765 param.Add("include_entities", "true");
767 return httpCon.GetContent(PostMethod,
768 this.CreateTwitterUri("/1.1/account/update_profile.json"),
775 public HttpStatusCode UpdateProfileImage(FileInfo imageFile, ref string content)
777 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
778 binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile));
780 return httpCon.GetContent(PostMethod,
781 this.CreateTwitterUri("/1.1/account/update_profile_image.json"),
789 public HttpStatusCode GetBlockUserIds(ref string content, long? cursor)
791 var param = new Dictionary<string, string>();
794 param.Add("cursor", cursor.ToString());
796 return httpCon.GetContent(GetMethod,
797 this.CreateTwitterUri("/1.1/blocks/ids.json"),
800 this.CreateRatelimitHeadersDict(),
801 this.CreateApiCalllback("/blocks/ids"));
804 public HttpStatusCode GetMuteUserIds(ref string content, long? cursor)
806 var param = new Dictionary<string, string>();
809 param.Add("cursor", cursor.ToString());
811 return httpCon.GetContent(GetMethod,
812 this.CreateTwitterUri("/1.1/mutes/users/ids.json"),
815 this.CreateRatelimitHeadersDict(),
816 this.CreateApiCalllback("/1.1/mutes/users/ids"));
819 public HttpStatusCode GetConfiguration(ref string content)
821 return httpCon.GetContent(GetMethod,
822 this.CreateTwitterUri("/1.1/help/configuration.json"),
825 this.CreateRatelimitHeadersDict(),
826 this.CreateApiCalllback("/help/configuration"));
829 public HttpStatusCode VerifyCredentials(ref string content)
831 return httpCon.GetContent(GetMethod,
832 this.CreateTwitterUri("/1.1/account/verify_credentials.json"),
835 this.CreateRatelimitHeadersDict(),
836 this.CreateApiCalllback("/account/verify_credentials"));
840 private static string _twitterUrl = "api.twitter.com";
841 private static string _twitterUserStreamUrl = "userstream.twitter.com";
842 private static string _twitterStreamUrl = "stream.twitter.com";
844 private Uri CreateTwitterUri(string path)
846 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUrl, path));
849 private Uri CreateTwitterUserStreamUri(string path)
851 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUserStreamUrl, path));
854 private Uri CreateTwitterStreamUri(string path)
856 return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
859 public static string TwitterUrl
864 HttpOAuthApiProxy.ProxyHost = value;
869 private Dictionary<string, string> CreateRatelimitHeadersDict()
871 return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
873 {"X-Access-Level", ""},
874 {"X-RateLimit-Limit", ""},
875 {"X-RateLimit-Remaining", ""},
876 {"X-RateLimit-Reset", ""},
877 {"X-Rate-Limit-Limit", ""},
878 {"X-Rate-Limit-Remaining", ""},
879 {"X-Rate-Limit-Reset", ""},
880 {"X-MediaRateLimit-Limit", ""},
881 {"X-MediaRateLimit-Remaining", ""},
882 {"X-MediaRateLimit-Reset", ""},
886 private CallbackDelegate CreateApiCalllback(string endpointName)
888 return (sender, code, headerInfo, content) =>
890 if (code < HttpStatusCode.InternalServerError)
891 MyCommon.TwitterApiInfo.UpdateFromHeader(headerInfo, endpointName);
895 public HttpStatusCode UserStream(ref Stream content,
900 Dictionary<string, string> param = new Dictionary<string, string>();
903 param.Add("replies", "all");
905 if (!string.IsNullOrEmpty(trackwords))
906 param.Add("track", trackwords);
908 return httpCon.GetContent(GetMethod,
909 this.CreateTwitterUserStreamUri("/1.1/user.json"),
915 public HttpStatusCode FilterStream(ref Stream content,
919 //文中の日本語キーワードに反応せず、使えない(スペースで分かち書きしてないと反応しない)
920 Dictionary<string, string> param = new Dictionary<string, string>();
922 if (!string.IsNullOrEmpty(trackwords))
923 param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray())));
925 return httpCon.GetContent(PostMethod,
926 this.CreateTwitterStreamUri("/1.1/statuses/filter.json"),
932 public void RequestAbort()
934 httpCon.RequestAbort();
937 public object Clone()
939 HttpTwitter myCopy = new HttpTwitter();
940 myCopy.Initialize(this.AccessToken, this.AccessTokenSecret, this.AuthenticatedUsername, this.AuthenticatedUserId);