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 static string _protocol = "http://";
49 private const string PostMethod = "POST";
50 private const string GetMethod = "GET";
52 private IHttpConnection httpCon; //HttpConnectionApi or HttpConnectionOAuth
53 private HttpVarious httpConVar = new HttpVarious();
55 private enum AuthMethod
60 private AuthMethod connectionType = AuthMethod.Basic;
62 private string requestToken;
64 private static string tk = "";
65 private static string tks = "";
66 private static string un = "";
68 public void Initialize(string accessToken,
69 string accessTokenSecret,
74 HttpOAuthApiProxy con = new HttpOAuthApiProxy();
75 if (tk != accessToken || tks != accessTokenSecret ||
76 un != username || connectionType != AuthMethod.OAuth)
78 // 以前の認証状態よりひとつでも変化があったらhttpヘッダより読み取ったカウントは初期化
80 tks = accessTokenSecret;
83 con.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret, accessToken, accessTokenSecret, username, userId, "screen_name", "user_id");
85 connectionType = AuthMethod.OAuth;
89 public string AccessToken
94 return ((HttpConnectionOAuth)httpCon).AccessToken;
100 public string AccessTokenSecret
105 return ((HttpConnectionOAuth)httpCon).AccessTokenSecret;
111 public string AuthenticatedUsername
116 return httpCon.AuthUsername;
122 public long AuthenticatedUserId
127 return httpCon.AuthUserId;
134 httpCon.AuthUserId = value;
138 public string Password
146 public bool AuthGetRequestToken(ref string content)
149 bool result = ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlowRequest(RequestTokenUrl, AuthorizeUrl, ref requestToken, ref authUri);
150 content = authUri.ToString();
154 public HttpStatusCode AuthGetAccessToken(string pin)
156 return ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlow(AccessTokenUrl, requestToken, pin);
159 public HttpStatusCode AuthUserAndPass(string username, string password, ref string content)
161 return httpCon.Authenticate(new Uri(AccessTokenUrlXAuth), username, password, ref content);
164 public void ClearAuthInfo()
166 this.Initialize("", "", "", 0);
169 public static bool UseSsl
174 _protocol = "https://";
176 _protocol = "http://";
180 public HttpStatusCode UpdateStatus(string status, long replyToId, ref string content)
182 Dictionary<string, string> param = new Dictionary<string, string>();
183 param.Add("status", status);
184 if (replyToId > 0) param.Add("in_reply_to_status_id", replyToId.ToString());
185 param.Add("include_entities", "true");
186 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
188 return httpCon.GetContent(PostMethod,
189 CreateTwitterUri("/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 > 0) 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 new Uri("https://upload.twitter.com/1/statuses/update_with_media.json"),
213 MyCommon.TwitterApiInfo.HttpHeaders,
217 public HttpStatusCode DestroyStatus(long id)
219 string content = null;
221 return httpCon.GetContent(PostMethod,
222 CreateTwitterUri("/1/statuses/destroy/" + id.ToString()+ ".json"),
229 public HttpStatusCode SendDirectMessage(string status, string sendto, ref string content)
231 Dictionary<string, string> param = new Dictionary<string, string>();
232 param.Add("text", status);
233 param.Add("screen_name", sendto);
234 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
236 return httpCon.GetContent(PostMethod,
237 CreateTwitterUri("/1/direct_messages/new.json"),
244 public HttpStatusCode DestroyDirectMessage(long id)
246 string content = null;
248 return httpCon.GetContent(PostMethod,
249 CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString()+ ".json"),
256 public HttpStatusCode RetweetStatus(long id, ref string content)
258 Dictionary<string, string> param = new Dictionary<string, string>();
259 param.Add("include_entities", "true");
261 return httpCon.GetContent(PostMethod,
262 CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".json"),
269 public HttpStatusCode ShowUserInfo(string screenName, ref string content)
271 Dictionary<string, string> param = new Dictionary<string, string>();
272 param.Add("screen_name", screenName);
273 param.Add("include_entities", "true");
274 return httpCon.GetContent(GetMethod,
275 CreateTwitterUri("/1/users/show.json"),
278 MyCommon.TwitterApiInfo.HttpHeaders,
282 public HttpStatusCode CreateFriendships(string screenName, ref string content)
284 Dictionary<string, string> param = new Dictionary<string, string>();
285 param.Add("screen_name", screenName);
287 return httpCon.GetContent(PostMethod,
288 CreateTwitterUri("/1/friendships/create.json"),
295 public HttpStatusCode DestroyFriendships(string screenName, ref string content)
297 Dictionary<string, string> param = new Dictionary<string, string>();
298 param.Add("screen_name", screenName);
300 return httpCon.GetContent(PostMethod,
301 CreateTwitterUri("/1/friendships/destroy.json"),
308 public HttpStatusCode CreateBlock(string screenName, ref string content)
310 Dictionary<string, string> param = new Dictionary<string, string>();
311 param.Add("screen_name", screenName);
313 return httpCon.GetContent(PostMethod,
314 CreateTwitterUri("/1/blocks/create.json"),
321 public HttpStatusCode DestroyBlock(string screenName, ref string content)
323 Dictionary<string, string> param = new Dictionary<string, string>();
324 param.Add("screen_name", screenName);
326 return httpCon.GetContent(PostMethod,
327 CreateTwitterUri("/1/blocks/destroy.json"),
334 public HttpStatusCode ReportSpam(string screenName, ref string content)
336 Dictionary<string, string> param = new Dictionary<string, string>();
337 param.Add("screen_name", screenName);
339 return httpCon.GetContent(PostMethod,
340 CreateTwitterUri("/1/report_spam.json"),
347 public HttpStatusCode ShowFriendships(string souceScreenName, string targetScreenName, ref string content)
349 Dictionary<string, string> param = new Dictionary<string, string>();
350 param.Add("source_screen_name", souceScreenName);
351 param.Add("target_screen_name", targetScreenName);
353 return httpCon.GetContent(GetMethod,
354 CreateTwitterUri("/1/friendships/show.json"),
357 MyCommon.TwitterApiInfo.HttpHeaders,
361 public HttpStatusCode ShowStatuses(long id, ref string content)
363 Dictionary<string, string> param = new Dictionary<string, string>();
364 param.Add("include_entities", "true");
365 return httpCon.GetContent(GetMethod,
366 CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".json"),
369 MyCommon.TwitterApiInfo.HttpHeaders,
373 public HttpStatusCode CreateFavorites(long id, ref string content)
375 return httpCon.GetContent(PostMethod,
376 CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".json"),
383 public HttpStatusCode DestroyFavorites(long id, ref string content)
385 return httpCon.GetContent(PostMethod,
386 CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".json"),
393 public HttpStatusCode HomeTimeline(int count, long max_id, long since_id, ref string content)
395 Dictionary<string, string> param = new Dictionary<string, string>();
397 param.Add("count", count.ToString());
399 param.Add("max_id", max_id.ToString());
401 param.Add("since_id", since_id.ToString());
403 param.Add("include_entities", "true");
405 return httpCon.GetContent(GetMethod,
406 CreateTwitterUri("/1/statuses/home_timeline.json"),
409 MyCommon.TwitterApiInfo.HttpHeaders,
413 public HttpStatusCode UserTimeline(long user_id, string screen_name, int count, long max_id, long since_id, ref string content)
415 Dictionary<string, string> param = new Dictionary<string, string>();
417 if ((user_id == 0 && string.IsNullOrEmpty(screen_name)) ||
418 (user_id != 0 && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
421 param.Add("user_id", user_id.ToString());
422 if (!string.IsNullOrEmpty(screen_name))
423 param.Add("screen_name", screen_name);
425 param.Add("count", count.ToString());
427 param.Add("max_id", max_id.ToString());
429 param.Add("since_id", since_id.ToString());
431 param.Add("include_rts", "true");
432 param.Add("include_entities", "true");
434 return httpCon.GetContent(GetMethod,
435 CreateTwitterUri("/1/statuses/user_timeline.json"),
438 MyCommon.TwitterApiInfo.HttpHeaders,
442 public HttpStatusCode PublicTimeline(int count, long max_id, long since_id, ref string content)
444 Dictionary<string, string> param = new Dictionary<string, string>();
446 param.Add("count", count.ToString());
448 param.Add("max_id", max_id.ToString());
450 param.Add("since_id", since_id.ToString());
452 param.Add("include_entities", "true");
454 return httpCon.GetContent(GetMethod,
455 CreateTwitterUri("/1/statuses/public_timeline.json"),
458 MyCommon.TwitterApiInfo.HttpHeaders,
462 public HttpStatusCode Mentions(int count, long max_id, long since_id, ref string content)
464 Dictionary<string, string> param = new Dictionary<string, string>();
466 param.Add("count", count.ToString());
468 param.Add("max_id", max_id.ToString());
470 param.Add("since_id", since_id.ToString());
472 param.Add("include_entities", "true");
474 return httpCon.GetContent(GetMethod,
475 CreateTwitterUri("/1/statuses/mentions.json"),
478 MyCommon.TwitterApiInfo.HttpHeaders,
482 public HttpStatusCode DirectMessages(int count, long max_id, long since_id, ref string content)
484 Dictionary<string, string> param = new Dictionary<string, string>();
486 param.Add("count", count.ToString());
488 param.Add("max_id", max_id.ToString());
490 param.Add("since_id", since_id.ToString());
491 param.Add("include_entities", "true");
493 return httpCon.GetContent(GetMethod,
494 CreateTwitterUri("/1/direct_messages.json"),
497 MyCommon.TwitterApiInfo.HttpHeaders,
501 public HttpStatusCode DirectMessagesSent(int count, long max_id, long since_id, ref string content)
503 Dictionary<string, string> param = new Dictionary<string, string>();
505 param.Add("count", count.ToString());
507 param.Add("max_id", max_id.ToString());
509 param.Add("since_id", since_id.ToString());
510 param.Add("include_entities", "true");
512 return httpCon.GetContent(GetMethod,
513 CreateTwitterUri("/1/direct_messages/sent.json"),
516 MyCommon.TwitterApiInfo.HttpHeaders,
520 public HttpStatusCode Favorites(int count, int page, ref string content)
522 Dictionary<string, string> param = new Dictionary<string, string>();
523 if (count != 20) param.Add("count", count.ToString());
527 param.Add("page", page.ToString());
530 param.Add("include_entities", "true");
532 return httpCon.GetContent(GetMethod,
533 CreateTwitterUri("/1/favorites.json"),
536 MyCommon.TwitterApiInfo.HttpHeaders,
540 public HttpStatusCode PhoenixSearch(string querystr, ref string content)
542 Dictionary<string, string> param = new Dictionary<string, string>();
545 if (string.IsNullOrEmpty(querystr)) return HttpStatusCode.BadRequest;
547 tmp = querystr.Split(new char[] {'?', '&'}, StringSplitOptions.RemoveEmptyEntries);
548 foreach (string tmp2 in tmp)
550 paramstr = tmp2.Split(new char[] {'='});
551 param.Add(paramstr[0], paramstr[1]);
554 return httpConVar.GetContent(GetMethod,
555 CreateTwitterUri("/phoenix_search.phoenix"),
559 MyCommon.GetAssemblyName());
562 public HttpStatusCode PhoenixSearch(string words, string lang, int rpp, int page, long sinceId, ref string content)
564 Dictionary<string, string> param = new Dictionary<string, string>();
565 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
566 param.Add("include_entities", "1");
567 param.Add("contributor_details", "true");
568 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
569 if (rpp > 0) param.Add("rpp", rpp.ToString());
570 if (page > 0) param.Add("page", page.ToString());
571 if (sinceId > 0) param.Add("since_id", sinceId.ToString());
573 if (param.Count == 0) return HttpStatusCode.BadRequest;
575 return httpConVar.GetContent(GetMethod,
576 CreateTwitterUri("/phoenix_search.phoenix"),
580 MyCommon.GetAssemblyName());
583 public HttpStatusCode Search(string words, string lang, int rpp, int page, long sinceId, ref string content)
585 Dictionary<string, string> param = new Dictionary<string, string>();
586 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
587 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
588 if (rpp > 0) param.Add("rpp", rpp.ToString());
589 if (page > 0) param.Add("page", page.ToString());
590 if (sinceId > 0) param.Add("since_id", sinceId.ToString());
592 if (param.Count == 0) return HttpStatusCode.BadRequest;
594 return httpConVar.GetContent(GetMethod,
595 CreateTwitterSearchUri("/search.atom"),
599 MyCommon.GetAssemblyName());
602 public HttpStatusCode SavedSearches(ref string content)
604 return httpCon.GetContent(GetMethod,
605 CreateTwitterUri("/1/saved_searches.json"),
612 public HttpStatusCode FollowerIds(long cursor, ref string content)
614 Dictionary<string, string> param = new Dictionary<string, string>();
615 param.Add("cursor", cursor.ToString());
617 return httpCon.GetContent(GetMethod,
618 CreateTwitterUri("/1/followers/ids.json"),
621 MyCommon.TwitterApiInfo.HttpHeaders,
625 public HttpStatusCode NoRetweetIds(long cursor, ref string content)
627 Dictionary<string, string> param = new Dictionary<string, string>();
628 param.Add("cursor", cursor.ToString());
630 return httpCon.GetContent(GetMethod,
631 CreateTwitterUri("/1/friendships/no_retweet_ids.json"),
634 MyCommon.TwitterApiInfo.HttpHeaders,
638 public HttpStatusCode RateLimitStatus(ref string content)
640 return httpCon.GetContent(GetMethod,
641 CreateTwitterUri("/1/account/rate_limit_status.json"),
644 MyCommon.TwitterApiInfo.HttpHeaders,
649 public HttpStatusCode GetLists(string user, long cursor, ref string content)
651 Dictionary<string, string> param = new Dictionary<string, string>();
652 param.Add("screen_name", user);
653 param.Add("cursor", cursor.ToString());
654 return httpCon.GetContent(GetMethod,
655 CreateTwitterUri("/1/lists.json"),
658 MyCommon.TwitterApiInfo.HttpHeaders,
662 public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
664 string mode = "public";
668 Dictionary<string, string> param = new Dictionary<string, string>();
669 param.Add("screen_name", user);
670 param.Add("list_id", list_id);
671 if (name != null) param.Add("name", name);
672 if (mode != null) param.Add("mode", mode);
673 if (description != null) param.Add("description", description);
675 return httpCon.GetContent(PostMethod,
676 CreateTwitterUri("/1/lists/update.json"),
683 public HttpStatusCode DeleteListID(string user, string list_id, ref string content)
685 Dictionary<string, string> param = new Dictionary<string, string>();
686 param.Add("screen_name", user);
687 param.Add("list_id", list_id);
689 return httpCon.GetContent(PostMethod,
690 CreateTwitterUri("/1/lists/destroy.json"),
697 public HttpStatusCode GetListsSubscriptions(string user, long cursor, ref string content)
699 Dictionary<string, string> param = new Dictionary<string, string>();
700 param.Add("screen_name", user);
701 param.Add("cursor", cursor.ToString());
702 return httpCon.GetContent(GetMethod,
703 CreateTwitterUri("/1/lists/subscriptions.json"),
706 MyCommon.TwitterApiInfo.HttpHeaders,
710 public HttpStatusCode GetListsStatuses(long userId, long list_id, int per_page, long max_id, long since_id, Boolean isRTinclude, ref string content)
712 //認証なくても取得できるが、protectedユーザー分が抜ける
713 Dictionary<string, string> param = new Dictionary<string, string>();
714 param.Add("user_id", userId.ToString());
715 param.Add("list_id", list_id.ToString());
717 param.Add("include_rts", "true");
719 param.Add("per_page", per_page.ToString());
721 param.Add("max_id", max_id.ToString());
723 param.Add("since_id", since_id.ToString());
724 param.Add("include_entities", "true");
726 return httpCon.GetContent(GetMethod,
727 CreateTwitterUri("/1/lists/statuses.json"),
730 MyCommon.TwitterApiInfo.HttpHeaders,
734 public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
736 string mode = "public";
740 Dictionary<string, string> param = new Dictionary<string, string>();
741 param.Add("name", listname);
742 param.Add("mode", mode);
743 if (!string.IsNullOrEmpty(description))
744 param.Add("description", description);
746 return httpCon.GetContent(PostMethod,
747 CreateTwitterUri("/1/lists/create.json"),
754 public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
756 Dictionary<string, string> param = new Dictionary<string, string>();
757 param.Add("screen_name", user);
758 param.Add("list_id", list_id);
759 param.Add("cursor", cursor.ToString());
760 return httpCon.GetContent(GetMethod,
761 CreateTwitterUri("/1/lists/members.json"),
764 MyCommon.TwitterApiInfo.HttpHeaders,
768 public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
770 Dictionary<string, string> param = new Dictionary<string, string>();
771 param.Add("list_id", list_id);
772 param.Add("screen_name", memberName);
773 return httpCon.GetContent(PostMethod,
774 CreateTwitterUri("/1/lists/members/create.json"),
781 //public HttpStatusCode CreateListMembers(string user, string list_id, string memberName, ref string content)
783 // //正常に動かないので旧APIで様子見
784 // //Dictionary<string, string> param = new Dictionary<string, string>();
785 // //param.Add("screen_name", user)
786 // //param.Add("list_id", list_id)
787 // //param.Add("member_screen_name", memberName)
788 // //return httpCon.GetContent(PostMethod,
789 // // CreateTwitterUri("/1/lists/members/create.json"),
794 // Dictionary<string, string> param = new Dictionary<string, string>();
795 // param.Add("id", memberName)
796 // return httpCon.GetContent(PostMethod,
797 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
804 public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content)
806 Dictionary<string, string> param = new Dictionary<string, string>();
807 param.Add("screen_name", memberName);
808 param.Add("list_id", list_id);
809 return httpCon.GetContent(PostMethod,
810 CreateTwitterUri("/1/lists/members/destroy.json"),
817 //public HttpStatusCode DeleteListMembers(string user, string list_id, string memberName, ref string content)
819 // //Dictionary<string, string> param = new Dictionary<string, string>();
820 // //param.Add("screen_name", user)
821 // //param.Add("list_id", list_id)
822 // //param.Add("member_screen_name", memberName)
823 // //return httpCon.GetContent(PostMethod,
824 // // CreateTwitterUri("/1/lists/members/destroy.json"),
829 // Dictionary<string, string> param = new Dictionary<string, string>();
830 // param.Add("id", memberName)
831 // param.Add("_method", "DELETE")
832 // return httpCon.GetContent(PostMethod,
833 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
840 public HttpStatusCode ShowListMember(string list_id, string memberName, ref string content)
842 //新APIがmember_screen_nameもmember_user_idも無視して、自分のIDを返してくる。
843 //正式にドキュメントに反映されるまで旧APIを使用する
844 Dictionary<string, string> param = new Dictionary<string, string>();
845 param.Add("screen_name", memberName);
846 param.Add("list_id", list_id);
847 return httpCon.GetContent(GetMethod,
848 CreateTwitterUri("/1/lists/members/show.json"),
851 MyCommon.TwitterApiInfo.HttpHeaders,
853 //return httpCon.GetContent(GetMethod,
854 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members/" + id + ".json"),
857 // MyCommon.TwitterApiInfo.HttpHeaders,
862 public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int count, int page, ref string content)
864 Dictionary<string, string> param = new Dictionary<string, string>();
866 param.Add("count", count.ToString());
868 param.Add("page", page.ToString());
870 return httpCon.GetContent(GetMethod,
871 CreateTwitterUri("/1/statuses/" + statusid.ToString()+ "/retweeted_by/ids.json"),
874 MyCommon.TwitterApiInfo.HttpHeaders,
878 public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content)
880 Dictionary<string, string> param = new Dictionary<string, string>();
882 param.Add("name", name);
883 param.Add("url", url);
884 param.Add("location", location);
885 param.Add("description", description);
886 param.Add("include_entities", "true");
888 return httpCon.GetContent(PostMethod,
889 CreateTwitterUri("/1/account/update_profile.json"),
896 public HttpStatusCode UpdateProfileImage(FileInfo imageFile, ref string content)
898 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
899 binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile));
901 return httpCon.GetContent(PostMethod,
902 CreateTwitterUri("/1/account/update_profile_image.json"),
910 public HttpStatusCode GetRelatedResults(long id, ref string content)
912 //認証なくても取得できるが、protectedユーザー分が抜ける
913 Dictionary<string, string> param = new Dictionary<string, string>();
915 param.Add("include_entities", "true");
917 return httpCon.GetContent(GetMethod,
918 CreateTwitterUri("/1/related_results/show/" + id.ToString()+ ".json"),
921 MyCommon.TwitterApiInfo.HttpHeaders,
925 public HttpStatusCode GetBlockUserIds(ref string content)
927 return httpCon.GetContent(GetMethod,
928 CreateTwitterUri("/1/blocks/blocking/ids.json"),
931 MyCommon.TwitterApiInfo.HttpHeaders,
935 public HttpStatusCode GetConfiguration(ref string content)
937 return httpCon.GetContent(GetMethod,
938 CreateTwitterUri("/1/help/configuration.json"),
941 MyCommon.TwitterApiInfo.HttpHeaders,
945 public HttpStatusCode VerifyCredentials(ref string content)
947 return httpCon.GetContent(GetMethod,
948 CreateTwitterUri("/1/account/verify_credentials.json"),
951 MyCommon.TwitterApiInfo.HttpHeaders,
956 private static string _twitterUrl = "api.twitter.com";
957 private static string _TwitterSearchUrl = "search.twitter.com";
958 private static string _twitterUserStreamUrl = "userstream.twitter.com";
959 private static string _twitterStreamUrl = "stream.twitter.com";
961 private Uri CreateTwitterUri(string path)
963 return new Uri(string.Format("{0}{1}{2}", _protocol, _twitterUrl, path));
966 private Uri CreateTwitterSearchUri(string path)
968 return new Uri(string.Format("{0}{1}{2}", _protocol, _TwitterSearchUrl, path));
971 private Uri CreateTwitterUserStreamUri(string path)
973 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUserStreamUrl, path));
976 private Uri CreateTwitterStreamUri(string path)
978 return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
981 public static string TwitterUrl
986 HttpOAuthApiProxy.ProxyHost = value;
990 public static string TwitterSearchUrl
994 _TwitterSearchUrl = value;
999 private void GetApiCallback(Object sender, ref HttpStatusCode code, ref string content)
1001 if (code < HttpStatusCode.InternalServerError)
1002 MyCommon.TwitterApiInfo.ParseHttpHeaders(MyCommon.TwitterApiInfo.HttpHeaders);
1005 public HttpStatusCode UserStream(ref Stream content,
1010 Dictionary<string, string> param = new Dictionary<string, string>();
1013 param.Add("replies", "all");
1015 if (!string.IsNullOrEmpty(trackwords))
1016 param.Add("track", trackwords);
1018 return httpCon.GetContent(GetMethod,
1019 CreateTwitterUserStreamUri("/2/user.json"),
1025 public HttpStatusCode FilterStream(ref Stream content,
1029 //文中の日本語キーワードに反応せず、使えない(スペースで分かち書きしてないと反応しない)
1030 Dictionary<string, string> param = new Dictionary<string, string>();
1032 if (!string.IsNullOrEmpty(trackwords))
1033 param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray())));
1035 return httpCon.GetContent(PostMethod,
1036 CreateTwitterStreamUri("/1/statuses/filter.json"),
1042 public void RequestAbort()
1044 httpCon.RequestAbort();
1047 public object Clone()
1049 HttpTwitter myCopy = new HttpTwitter();
1050 myCopy.Initialize(this.AccessToken, this.AccessTokenSecret, this.AuthenticatedUsername, this.AuthenticatedUserId);