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, List<long> mediaIds, 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 if (mediaIds != null)
177 StringBuilder sb = new StringBuilder();
178 foreach (var idStr in mediaIds.Select(x => x.ToString()))
180 if (string.IsNullOrEmpty(idStr)) continue;
181 if (sb.Length > 0) sb.Append(",");
185 if (sb.Length > 0) param.Add("media_ids", sb.ToString());
188 return httpCon.GetContent(PostMethod,
189 this.CreateTwitterUri("/1.1/statuses/update.json"),
196 public HttpStatusCode UpdateStatusWithMedia(string status, long? replyToId, FileInfo mediaFile, ref string content)
199 Dictionary<string, string> param = new Dictionary<string, string>();
200 param.Add("status", status);
201 if (replyToId != null) param.Add("in_reply_to_status_id", replyToId.ToString());
202 param.Add("include_entities", "true");
203 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
205 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
206 binary.Add(new KeyValuePair<string, FileInfo>("media[]", mediaFile));
208 return httpCon.GetContent(PostMethod,
209 this.CreateTwitterUri("/1.1/statuses/update_with_media.json"),
213 this.CreateRatelimitHeadersDict(),
214 this.CreateApiCalllback("/statuses/update_with_media"));
217 public HttpStatusCode UploadMedia(FileInfo mediaFile, ref string content)
220 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
221 binary.Add(new KeyValuePair<string, FileInfo>("media", mediaFile));
223 return httpCon.GetContent(PostMethod,
224 this.CreateTwitterUploadUri("/1.1/media/upload.json"),
232 public HttpStatusCode DestroyStatus(long id)
234 string content = null;
236 return httpCon.GetContent(PostMethod,
237 this.CreateTwitterUri("/1.1/statuses/destroy/" + id + ".json"),
244 public HttpStatusCode SendDirectMessage(string status, string sendto, ref string content)
246 Dictionary<string, string> param = new Dictionary<string, string>();
247 param.Add("text", status);
248 param.Add("screen_name", sendto);
249 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
251 return httpCon.GetContent(PostMethod,
252 this.CreateTwitterUri("/1.1/direct_messages/new.json"),
259 public HttpStatusCode DestroyDirectMessage(long id)
261 string content = null;
263 var param = new Dictionary<string, string>();
264 param.Add("id", id.ToString());
266 return httpCon.GetContent(PostMethod,
267 this.CreateTwitterUri("/1.1/direct_messages/destroy.json"),
274 public HttpStatusCode RetweetStatus(long id, ref string content)
276 Dictionary<string, string> param = new Dictionary<string, string>();
277 param.Add("include_entities", "true");
279 return httpCon.GetContent(PostMethod,
280 this.CreateTwitterUri("/1.1/statuses/retweet/" + id + ".json"),
287 public HttpStatusCode ShowUserInfo(string screenName, ref string content)
289 Dictionary<string, string> param = new Dictionary<string, string>();
290 param.Add("screen_name", screenName);
291 param.Add("include_entities", "true");
292 return httpCon.GetContent(GetMethod,
293 this.CreateTwitterUri("/1.1/users/show.json"),
296 this.CreateRatelimitHeadersDict(),
297 this.CreateApiCalllback("/users/show/:id"));
300 public HttpStatusCode CreateFriendships(string screenName, ref string content)
302 Dictionary<string, string> param = new Dictionary<string, string>();
303 param.Add("screen_name", screenName);
305 return httpCon.GetContent(PostMethod,
306 this.CreateTwitterUri("/1.1/friendships/create.json"),
313 public HttpStatusCode DestroyFriendships(string screenName, ref string content)
315 Dictionary<string, string> param = new Dictionary<string, string>();
316 param.Add("screen_name", screenName);
318 return httpCon.GetContent(PostMethod,
319 this.CreateTwitterUri("/1.1/friendships/destroy.json"),
326 public HttpStatusCode CreateBlock(string screenName, ref string content)
328 Dictionary<string, string> param = new Dictionary<string, string>();
329 param.Add("screen_name", screenName);
331 return httpCon.GetContent(PostMethod,
332 this.CreateTwitterUri("/1.1/blocks/create.json"),
339 public HttpStatusCode DestroyBlock(string screenName, ref string content)
341 Dictionary<string, string> param = new Dictionary<string, string>();
342 param.Add("screen_name", screenName);
344 return httpCon.GetContent(PostMethod,
345 this.CreateTwitterUri("/1.1/blocks/destroy.json"),
352 public HttpStatusCode ReportSpam(string screenName, ref string content)
354 Dictionary<string, string> param = new Dictionary<string, string>();
355 param.Add("screen_name", screenName);
357 return httpCon.GetContent(PostMethod,
358 this.CreateTwitterUri("/1.1/users/report_spam.json"),
365 public HttpStatusCode ShowFriendships(string souceScreenName, string targetScreenName, ref string content)
367 Dictionary<string, string> param = new Dictionary<string, string>();
368 param.Add("source_screen_name", souceScreenName);
369 param.Add("target_screen_name", targetScreenName);
371 return httpCon.GetContent(GetMethod,
372 this.CreateTwitterUri("/1.1/friendships/show.json"),
375 this.CreateRatelimitHeadersDict(),
376 this.CreateApiCalllback("/friendships/show"));
379 public HttpStatusCode ShowStatuses(long id, ref string content)
381 Dictionary<string, string> param = new Dictionary<string, string>();
382 param.Add("include_entities", "true");
383 return httpCon.GetContent(GetMethod,
384 this.CreateTwitterUri("/1.1/statuses/show/" + id + ".json"),
387 this.CreateRatelimitHeadersDict(),
388 this.CreateApiCalllback("/statuses/show/:id"));
391 public HttpStatusCode CreateFavorites(long id, ref string content)
393 var param = new Dictionary<string, string>();
394 param.Add("id", id.ToString());
396 return httpCon.GetContent(PostMethod,
397 this.CreateTwitterUri("/1.1/favorites/create.json"),
404 public HttpStatusCode DestroyFavorites(long id, ref string content)
406 var param = new Dictionary<string, string>();
407 param.Add("id", id.ToString());
409 return httpCon.GetContent(PostMethod,
410 this.CreateTwitterUri("/1.1/favorites/destroy.json"),
417 public HttpStatusCode HomeTimeline(int? count, long? max_id, long? since_id, ref string content)
419 Dictionary<string, string> param = new Dictionary<string, string>();
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_entities", "true");
429 return httpCon.GetContent(GetMethod,
430 this.CreateTwitterUri("/1.1/statuses/home_timeline.json"),
433 this.CreateRatelimitHeadersDict(),
434 this.CreateApiCalllback("/statuses/home_timeline"));
437 public HttpStatusCode UserTimeline(long? user_id, string screen_name, int? count, long? max_id, long? since_id, ref string content)
439 Dictionary<string, string> param = new Dictionary<string, string>();
441 if ((user_id == null && string.IsNullOrEmpty(screen_name)) ||
442 (user_id != null && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
445 param.Add("user_id", user_id.ToString());
446 if (!string.IsNullOrEmpty(screen_name))
447 param.Add("screen_name", screen_name);
449 param.Add("count", count.ToString());
451 param.Add("max_id", max_id.ToString());
452 if (since_id != null)
453 param.Add("since_id", since_id.ToString());
455 param.Add("include_rts", "true");
456 param.Add("include_entities", "true");
458 return httpCon.GetContent(GetMethod,
459 this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
462 this.CreateRatelimitHeadersDict(),
463 this.CreateApiCalllback("/statuses/user_timeline"));
466 public HttpStatusCode Mentions(int? count, long? max_id, long? since_id, ref string content)
468 Dictionary<string, string> param = new Dictionary<string, string>();
470 param.Add("count", count.ToString());
472 param.Add("max_id", max_id.ToString());
473 if (since_id != null)
474 param.Add("since_id", since_id.ToString());
476 param.Add("include_entities", "true");
478 return httpCon.GetContent(GetMethod,
479 this.CreateTwitterUri("/1.1/statuses/mentions_timeline.json"),
482 this.CreateRatelimitHeadersDict(),
483 this.CreateApiCalllback("/statuses/mentions_timeline"));
486 public HttpStatusCode DirectMessages(int? count, long? max_id, long? since_id, ref string content)
488 Dictionary<string, string> param = new Dictionary<string, string>();
490 param.Add("count", count.ToString());
492 param.Add("max_id", max_id.ToString());
493 if (since_id != null)
494 param.Add("since_id", since_id.ToString());
495 param.Add("include_entities", "true");
497 return httpCon.GetContent(GetMethod,
498 this.CreateTwitterUri("/1.1/direct_messages.json"),
501 this.CreateRatelimitHeadersDict(),
502 this.CreateApiCalllback("/direct_messages"));
505 public HttpStatusCode DirectMessagesSent(int? count, long? max_id, long? since_id, ref string content)
507 Dictionary<string, string> param = new Dictionary<string, string>();
509 param.Add("count", count.ToString());
511 param.Add("max_id", max_id.ToString());
512 if (since_id != null)
513 param.Add("since_id", since_id.ToString());
514 param.Add("include_entities", "true");
516 return httpCon.GetContent(GetMethod,
517 this.CreateTwitterUri("/1.1/direct_messages/sent.json"),
520 this.CreateRatelimitHeadersDict(),
521 this.CreateApiCalllback("/direct_messages/sent"));
524 public HttpStatusCode Favorites(int? count, int? page, ref string content)
526 Dictionary<string, string> param = new Dictionary<string, string>();
527 if (count != null) param.Add("count", count.ToString());
531 param.Add("page", page.ToString());
534 param.Add("include_entities", "true");
536 return httpCon.GetContent(GetMethod,
537 this.CreateTwitterUri("/1.1/favorites/list.json"),
540 this.CreateRatelimitHeadersDict(),
541 this.CreateApiCalllback("/favorites/list"));
544 public HttpStatusCode Search(string words, string lang, int? count, long? maxId, long? sinceId, ref string content)
546 Dictionary<string, string> param = new Dictionary<string, string>();
547 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
548 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
549 if (count != null) param.Add("count", count.ToString());
550 if (maxId != null) param.Add("max_id", maxId.ToString());
551 if (sinceId != null) param.Add("since_id", sinceId.ToString());
553 if (param.Count == 0) return HttpStatusCode.BadRequest;
555 param.Add("result_type", "recent");
556 param.Add("include_entities", "true");
557 return httpCon.GetContent(GetMethod,
558 this.CreateTwitterUri("/1.1/search/tweets.json"),
561 this.CreateRatelimitHeadersDict(),
562 this.CreateApiCalllback("/search/tweets"));
565 public HttpStatusCode SavedSearches(ref string content)
567 return httpCon.GetContent(GetMethod,
568 this.CreateTwitterUri("/1.1/saved_searches/list.json"),
571 this.CreateRatelimitHeadersDict(),
572 this.CreateApiCalllback("/saved_searches/list"));
575 public HttpStatusCode FollowerIds(long cursor, ref string content)
577 Dictionary<string, string> param = new Dictionary<string, string>();
578 param.Add("cursor", cursor.ToString());
580 return httpCon.GetContent(GetMethod,
581 this.CreateTwitterUri("/1.1/followers/ids.json"),
584 this.CreateRatelimitHeadersDict(),
585 this.CreateApiCalllback("/followers/ids"));
588 public HttpStatusCode NoRetweetIds(ref string content)
590 return httpCon.GetContent(GetMethod,
591 this.CreateTwitterUri("/1.1/friendships/no_retweets/ids.json"),
594 this.CreateRatelimitHeadersDict(),
595 this.CreateApiCalllback("/friendships/no_retweets/ids"));
598 public HttpStatusCode RateLimitStatus(ref string content)
600 return httpCon.GetContent(GetMethod,
601 this.CreateTwitterUri("/1.1/application/rate_limit_status.json"),
604 this.CreateRatelimitHeadersDict(),
605 this.CreateApiCalllback("/application/rate_limit_status"));
609 public HttpStatusCode GetLists(string user, ref string content)
611 Dictionary<string, string> param = new Dictionary<string, string>();
612 param.Add("screen_name", user);
614 return httpCon.GetContent(GetMethod,
615 this.CreateTwitterUri("/1.1/lists/list.json"),
618 this.CreateRatelimitHeadersDict(),
619 this.CreateApiCalllback("/lists/list"));
622 public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
624 string mode = "public";
628 Dictionary<string, string> param = new Dictionary<string, string>();
629 param.Add("screen_name", user);
630 param.Add("list_id", list_id);
631 if (name != null) param.Add("name", name);
632 if (mode != null) param.Add("mode", mode);
633 if (description != null) param.Add("description", description);
635 return httpCon.GetContent(PostMethod,
636 this.CreateTwitterUri("/1.1/lists/update.json"),
643 public HttpStatusCode DeleteListID(string user, string list_id, ref string content)
645 Dictionary<string, string> param = new Dictionary<string, string>();
646 param.Add("screen_name", user);
647 param.Add("list_id", list_id);
649 return httpCon.GetContent(PostMethod,
650 this.CreateTwitterUri("/1.1/lists/destroy.json"),
657 public HttpStatusCode GetListsSubscriptions(string user, ref string content)
659 Dictionary<string, string> param = new Dictionary<string, string>();
660 param.Add("screen_name", user);
662 return httpCon.GetContent(GetMethod,
663 this.CreateTwitterUri("/1.1/lists/subscriptions.json"),
666 this.CreateRatelimitHeadersDict(),
667 this.CreateApiCalllback("/lists/subscriptions"));
670 public HttpStatusCode GetListsStatuses(long userId, long list_id, int? per_page, long? max_id, long? since_id, Boolean isRTinclude, ref string content)
672 //認証なくても取得できるが、protectedユーザー分が抜ける
673 Dictionary<string, string> param = new Dictionary<string, string>();
674 param.Add("user_id", userId.ToString());
675 param.Add("list_id", list_id.ToString());
676 param.Add("include_rts", isRTinclude ? "true" : "false");
677 if (per_page != null)
678 param.Add("count", per_page.ToString());
680 param.Add("max_id", max_id.ToString());
681 if (since_id != null)
682 param.Add("since_id", since_id.ToString());
683 param.Add("include_entities", "true");
685 return httpCon.GetContent(GetMethod,
686 this.CreateTwitterUri("/1.1/lists/statuses.json"),
689 this.CreateRatelimitHeadersDict(),
690 this.CreateApiCalllback("/lists/statuses"));
693 public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
695 string mode = "public";
699 Dictionary<string, string> param = new Dictionary<string, string>();
700 param.Add("name", listname);
701 param.Add("mode", mode);
702 if (!string.IsNullOrEmpty(description))
703 param.Add("description", description);
705 return httpCon.GetContent(PostMethod,
706 this.CreateTwitterUri("/1.1/lists/create.json"),
713 public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
715 Dictionary<string, string> param = new Dictionary<string, string>();
716 param.Add("screen_name", user);
717 param.Add("list_id", list_id);
718 param.Add("cursor", cursor.ToString());
719 return httpCon.GetContent(GetMethod,
720 this.CreateTwitterUri("/1.1/lists/members.json"),
723 this.CreateRatelimitHeadersDict(),
724 this.CreateApiCalllback("/lists/members"));
727 public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
729 Dictionary<string, string> param = new Dictionary<string, string>();
730 param.Add("list_id", list_id);
731 param.Add("screen_name", memberName);
732 return httpCon.GetContent(PostMethod,
733 this.CreateTwitterUri("/1.1/lists/members/create.json"),
740 public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content)
742 Dictionary<string, string> param = new Dictionary<string, string>();
743 param.Add("screen_name", memberName);
744 param.Add("list_id", list_id);
745 return httpCon.GetContent(PostMethod,
746 this.CreateTwitterUri("/1.1/lists/members/destroy.json"),
753 public HttpStatusCode ShowListMember(string list_id, string memberName, ref string content)
755 Dictionary<string, string> param = new Dictionary<string, string>();
756 param.Add("screen_name", memberName);
757 param.Add("list_id", list_id);
758 return httpCon.GetContent(GetMethod,
759 this.CreateTwitterUri("/1.1/lists/members/show.json"),
762 this.CreateRatelimitHeadersDict(),
763 this.CreateApiCalllback("/lists/members/show"));
767 public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int? count, int? page, ref string content)
769 Dictionary<string, string> param = new Dictionary<string, string>();
771 param.Add("count", count.ToString());
773 param.Add("page", page.ToString());
775 param.Add("id", statusid.ToString());
777 return httpCon.GetContent(GetMethod,
778 this.CreateTwitterUri("/1.1/statuses/retweeters/ids.json"),
781 this.CreateRatelimitHeadersDict(),
782 this.CreateApiCalllback("/statuses/retweeters/ids"));
785 public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content)
787 Dictionary<string, string> param = new Dictionary<string, string>();
789 param.Add("name", WebUtility.HtmlEncode(name));
790 param.Add("url", url);
791 param.Add("location", WebUtility.HtmlEncode(location));
792 param.Add("description", WebUtility.HtmlEncode(description));
793 param.Add("include_entities", "true");
795 return httpCon.GetContent(PostMethod,
796 this.CreateTwitterUri("/1.1/account/update_profile.json"),
803 public HttpStatusCode UpdateProfileImage(FileInfo imageFile, ref string content)
805 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
806 binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile));
808 return httpCon.GetContent(PostMethod,
809 this.CreateTwitterUri("/1.1/account/update_profile_image.json"),
817 public HttpStatusCode GetBlockUserIds(ref string content, long? cursor)
819 var param = new Dictionary<string, string>();
822 param.Add("cursor", cursor.ToString());
824 return httpCon.GetContent(GetMethod,
825 this.CreateTwitterUri("/1.1/blocks/ids.json"),
828 this.CreateRatelimitHeadersDict(),
829 this.CreateApiCalllback("/blocks/ids"));
832 public HttpStatusCode GetMuteUserIds(ref string content, long? cursor)
834 var param = new Dictionary<string, string>();
837 param.Add("cursor", cursor.ToString());
839 return httpCon.GetContent(GetMethod,
840 this.CreateTwitterUri("/1.1/mutes/users/ids.json"),
843 this.CreateRatelimitHeadersDict(),
844 this.CreateApiCalllback("/1.1/mutes/users/ids"));
847 public HttpStatusCode GetConfiguration(ref string content)
849 return httpCon.GetContent(GetMethod,
850 this.CreateTwitterUri("/1.1/help/configuration.json"),
853 this.CreateRatelimitHeadersDict(),
854 this.CreateApiCalllback("/help/configuration"));
857 public HttpStatusCode VerifyCredentials(ref string content)
859 return httpCon.GetContent(GetMethod,
860 this.CreateTwitterUri("/1.1/account/verify_credentials.json"),
863 this.CreateRatelimitHeadersDict(),
864 this.CreateApiCalllback("/account/verify_credentials"));
868 private static string _twitterUrl = "api.twitter.com";
869 private static string _twitterUserStreamUrl = "userstream.twitter.com";
870 private static string _twitterStreamUrl = "stream.twitter.com";
871 private static string _twitterUploadUrl = "upload.twitter.com";
873 private Uri CreateTwitterUri(string path)
875 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUrl, path));
878 private Uri CreateTwitterUserStreamUri(string path)
880 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUserStreamUrl, path));
883 private Uri CreateTwitterStreamUri(string path)
885 return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
888 private Uri CreateTwitterUploadUri(string path)
890 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUploadUrl, path));
893 public static string TwitterUrl
898 HttpOAuthApiProxy.ProxyHost = value;
903 private Dictionary<string, string> CreateRatelimitHeadersDict()
905 return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
907 {"X-Access-Level", ""},
908 {"X-RateLimit-Limit", ""},
909 {"X-RateLimit-Remaining", ""},
910 {"X-RateLimit-Reset", ""},
911 {"X-Rate-Limit-Limit", ""},
912 {"X-Rate-Limit-Remaining", ""},
913 {"X-Rate-Limit-Reset", ""},
914 {"X-MediaRateLimit-Limit", ""},
915 {"X-MediaRateLimit-Remaining", ""},
916 {"X-MediaRateLimit-Reset", ""},
920 private CallbackDelegate CreateApiCalllback(string endpointName)
922 return (sender, code, headerInfo, content) =>
924 if (code < HttpStatusCode.InternalServerError)
925 MyCommon.TwitterApiInfo.UpdateFromHeader(headerInfo, endpointName);
929 public HttpStatusCode UserStream(ref Stream content,
934 Dictionary<string, string> param = new Dictionary<string, string>();
937 param.Add("replies", "all");
939 if (!string.IsNullOrEmpty(trackwords))
940 param.Add("track", trackwords);
942 return httpCon.GetContent(GetMethod,
943 this.CreateTwitterUserStreamUri("/1.1/user.json"),
949 public HttpStatusCode FilterStream(ref Stream content,
953 //文中の日本語キーワードに反応せず、使えない(スペースで分かち書きしてないと反応しない)
954 Dictionary<string, string> param = new Dictionary<string, string>();
956 if (!string.IsNullOrEmpty(trackwords))
957 param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray())));
959 return httpCon.GetContent(PostMethod,
960 this.CreateTwitterStreamUri("/1.1/statuses/filter.json"),
966 public void RequestAbort()
968 httpCon.RequestAbort();
971 public object Clone()
973 HttpTwitter myCopy = new HttpTwitter();
974 myCopy.Initialize(this.AccessToken, this.AccessTokenSecret, this.AuthenticatedUsername, this.AuthenticatedUserId);