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 private Dictionary<string, string> apiStatusHeaders = new Dictionary<string, string>
70 {"X-Access-Level", ""},
71 {"X-RateLimit-Limit", ""},
72 {"X-RateLimit-Remaining", ""},
73 {"X-RateLimit-Reset", ""},
74 {"X-MediaRateLimit-Limit", ""},
75 {"X-MediaRateLimit-Remaining", ""},
76 {"X-MediaRateLimit-Reset", ""},
79 public void Initialize(string accessToken,
80 string accessTokenSecret,
85 HttpOAuthApiProxy con = new HttpOAuthApiProxy();
86 if (tk != accessToken || tks != accessTokenSecret ||
87 un != username || connectionType != AuthMethod.OAuth)
89 // 以前の認証状態よりひとつでも変化があったらhttpヘッダより読み取ったカウントは初期化
91 tks = accessTokenSecret;
94 con.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret, accessToken, accessTokenSecret, username, userId, "screen_name", "user_id");
96 connectionType = AuthMethod.OAuth;
100 public string AccessToken
105 return ((HttpConnectionOAuth)httpCon).AccessToken;
111 public string AccessTokenSecret
116 return ((HttpConnectionOAuth)httpCon).AccessTokenSecret;
122 public string AuthenticatedUsername
127 return httpCon.AuthUsername;
133 public long AuthenticatedUserId
138 return httpCon.AuthUserId;
145 httpCon.AuthUserId = value;
149 public string Password
157 public bool AuthGetRequestToken(ref string content)
160 bool result = ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlowRequest(RequestTokenUrl, AuthorizeUrl, ref requestToken, ref authUri);
161 content = authUri.ToString();
165 public HttpStatusCode AuthGetAccessToken(string pin)
167 return ((HttpOAuthApiProxy)httpCon).AuthenticatePinFlow(AccessTokenUrl, requestToken, pin);
170 public HttpStatusCode AuthUserAndPass(string username, string password, ref string content)
172 return httpCon.Authenticate(new Uri(AccessTokenUrlXAuth), username, password, ref content);
175 public void ClearAuthInfo()
177 this.Initialize("", "", "", 0);
180 public static bool UseSsl
185 _protocol = "https://";
187 _protocol = "http://";
191 public HttpStatusCode UpdateStatus(string status, long replyToId, ref string content)
193 Dictionary<string, string> param = new Dictionary<string, string>();
194 param.Add("status", status);
195 if (replyToId > 0) param.Add("in_reply_to_status_id", replyToId.ToString());
196 param.Add("include_entities", "true");
197 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
199 return httpCon.GetContent(PostMethod,
200 CreateTwitterUri("/1/statuses/update.json"),
207 public HttpStatusCode UpdateStatusWithMedia(string status, long replyToId, FileInfo mediaFile, ref string content)
210 Dictionary<string, string> param = new Dictionary<string, string>();
211 param.Add("status", status);
212 if (replyToId > 0) param.Add("in_reply_to_status_id", replyToId.ToString());
213 param.Add("include_entities", "true");
214 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
216 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
217 binary.Add(new KeyValuePair<string, FileInfo>("media[]", mediaFile));
219 return httpCon.GetContent(PostMethod,
220 new Uri("https://upload.twitter.com/1/statuses/update_with_media.json"),
224 this.apiStatusHeaders,
228 public HttpStatusCode DestroyStatus(long id)
230 string content = null;
232 return httpCon.GetContent(PostMethod,
233 CreateTwitterUri("/1/statuses/destroy/" + id.ToString()+ ".json"),
240 public HttpStatusCode SendDirectMessage(string status, string sendto, ref string content)
242 Dictionary<string, string> param = new Dictionary<string, string>();
243 param.Add("text", status);
244 param.Add("screen_name", sendto);
245 //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true")
247 return httpCon.GetContent(PostMethod,
248 CreateTwitterUri("/1/direct_messages/new.json"),
255 public HttpStatusCode DestroyDirectMessage(long id)
257 string content = null;
259 return httpCon.GetContent(PostMethod,
260 CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString()+ ".json"),
267 public HttpStatusCode RetweetStatus(long id, ref string content)
269 Dictionary<string, string> param = new Dictionary<string, string>();
270 param.Add("include_entities", "true");
272 return httpCon.GetContent(PostMethod,
273 CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".json"),
280 public HttpStatusCode ShowUserInfo(string screenName, ref string content)
282 Dictionary<string, string> param = new Dictionary<string, string>();
283 param.Add("screen_name", screenName);
284 param.Add("include_entities", "true");
285 return httpCon.GetContent(GetMethod,
286 CreateTwitterUri("/1/users/show.json"),
289 this.apiStatusHeaders,
293 public HttpStatusCode CreateFriendships(string screenName, ref string content)
295 Dictionary<string, string> param = new Dictionary<string, string>();
296 param.Add("screen_name", screenName);
298 return httpCon.GetContent(PostMethod,
299 CreateTwitterUri("/1/friendships/create.json"),
306 public HttpStatusCode DestroyFriendships(string screenName, ref string content)
308 Dictionary<string, string> param = new Dictionary<string, string>();
309 param.Add("screen_name", screenName);
311 return httpCon.GetContent(PostMethod,
312 CreateTwitterUri("/1/friendships/destroy.json"),
319 public HttpStatusCode CreateBlock(string screenName, ref string content)
321 Dictionary<string, string> param = new Dictionary<string, string>();
322 param.Add("screen_name", screenName);
324 return httpCon.GetContent(PostMethod,
325 CreateTwitterUri("/1/blocks/create.json"),
332 public HttpStatusCode DestroyBlock(string screenName, ref string content)
334 Dictionary<string, string> param = new Dictionary<string, string>();
335 param.Add("screen_name", screenName);
337 return httpCon.GetContent(PostMethod,
338 CreateTwitterUri("/1/blocks/destroy.json"),
345 public HttpStatusCode ReportSpam(string screenName, ref string content)
347 Dictionary<string, string> param = new Dictionary<string, string>();
348 param.Add("screen_name", screenName);
350 return httpCon.GetContent(PostMethod,
351 CreateTwitterUri("/1/report_spam.json"),
358 public HttpStatusCode ShowFriendships(string souceScreenName, string targetScreenName, ref string content)
360 Dictionary<string, string> param = new Dictionary<string, string>();
361 param.Add("source_screen_name", souceScreenName);
362 param.Add("target_screen_name", targetScreenName);
364 return httpCon.GetContent(GetMethod,
365 CreateTwitterUri("/1/friendships/show.json"),
368 this.apiStatusHeaders,
372 public HttpStatusCode ShowStatuses(long id, ref string content)
374 Dictionary<string, string> param = new Dictionary<string, string>();
375 param.Add("include_entities", "true");
376 return httpCon.GetContent(GetMethod,
377 CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".json"),
380 this.apiStatusHeaders,
384 public HttpStatusCode CreateFavorites(long id, ref string content)
386 return httpCon.GetContent(PostMethod,
387 CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".json"),
394 public HttpStatusCode DestroyFavorites(long id, ref string content)
396 return httpCon.GetContent(PostMethod,
397 CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".json"),
404 public HttpStatusCode HomeTimeline(int count, long max_id, long since_id, ref string content)
406 Dictionary<string, string> param = new Dictionary<string, string>();
408 param.Add("count", count.ToString());
410 param.Add("max_id", max_id.ToString());
412 param.Add("since_id", since_id.ToString());
414 param.Add("include_entities", "true");
416 return httpCon.GetContent(GetMethod,
417 CreateTwitterUri("/1/statuses/home_timeline.json"),
420 this.apiStatusHeaders,
424 public HttpStatusCode UserTimeline(long user_id, string screen_name, int count, long max_id, long since_id, ref string content)
426 Dictionary<string, string> param = new Dictionary<string, string>();
428 if ((user_id == 0 && string.IsNullOrEmpty(screen_name)) ||
429 (user_id != 0 && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
432 param.Add("user_id", user_id.ToString());
433 if (!string.IsNullOrEmpty(screen_name))
434 param.Add("screen_name", screen_name);
436 param.Add("count", count.ToString());
438 param.Add("max_id", max_id.ToString());
440 param.Add("since_id", since_id.ToString());
442 param.Add("include_rts", "true");
443 param.Add("include_entities", "true");
445 return httpCon.GetContent(GetMethod,
446 CreateTwitterUri("/1/statuses/user_timeline.json"),
449 this.apiStatusHeaders,
453 public HttpStatusCode PublicTimeline(int count, long max_id, long since_id, ref string content)
455 Dictionary<string, string> param = new Dictionary<string, string>();
457 param.Add("count", count.ToString());
459 param.Add("max_id", max_id.ToString());
461 param.Add("since_id", since_id.ToString());
463 param.Add("include_entities", "true");
465 return httpCon.GetContent(GetMethod,
466 CreateTwitterUri("/1/statuses/public_timeline.json"),
469 this.apiStatusHeaders,
473 public HttpStatusCode Mentions(int count, long max_id, long since_id, ref string content)
475 Dictionary<string, string> param = new Dictionary<string, string>();
477 param.Add("count", count.ToString());
479 param.Add("max_id", max_id.ToString());
481 param.Add("since_id", since_id.ToString());
483 param.Add("include_entities", "true");
485 return httpCon.GetContent(GetMethod,
486 CreateTwitterUri("/1/statuses/mentions.json"),
489 this.apiStatusHeaders,
493 public HttpStatusCode DirectMessages(int count, long max_id, long since_id, ref string content)
495 Dictionary<string, string> param = new Dictionary<string, string>();
497 param.Add("count", count.ToString());
499 param.Add("max_id", max_id.ToString());
501 param.Add("since_id", since_id.ToString());
502 param.Add("include_entities", "true");
504 return httpCon.GetContent(GetMethod,
505 CreateTwitterUri("/1/direct_messages.json"),
508 this.apiStatusHeaders,
512 public HttpStatusCode DirectMessagesSent(int count, long max_id, long since_id, ref string content)
514 Dictionary<string, string> param = new Dictionary<string, string>();
516 param.Add("count", count.ToString());
518 param.Add("max_id", max_id.ToString());
520 param.Add("since_id", since_id.ToString());
521 param.Add("include_entities", "true");
523 return httpCon.GetContent(GetMethod,
524 CreateTwitterUri("/1/direct_messages/sent.json"),
527 this.apiStatusHeaders,
531 public HttpStatusCode Favorites(int count, int page, ref string content)
533 Dictionary<string, string> param = new Dictionary<string, string>();
534 if (count != 20) param.Add("count", count.ToString());
538 param.Add("page", page.ToString());
541 param.Add("include_entities", "true");
543 return httpCon.GetContent(GetMethod,
544 CreateTwitterUri("/1/favorites.json"),
547 this.apiStatusHeaders,
551 public HttpStatusCode PhoenixSearch(string querystr, ref string content)
553 Dictionary<string, string> param = new Dictionary<string, string>();
556 if (string.IsNullOrEmpty(querystr)) return HttpStatusCode.BadRequest;
558 tmp = querystr.Split(new char[] {'?', '&'}, StringSplitOptions.RemoveEmptyEntries);
559 foreach (string tmp2 in tmp)
561 paramstr = tmp2.Split(new char[] {'='});
562 param.Add(paramstr[0], paramstr[1]);
565 return httpConVar.GetContent(GetMethod,
566 CreateTwitterUri("/phoenix_search.phoenix"),
570 MyCommon.GetAssemblyName());
573 public HttpStatusCode PhoenixSearch(string words, string lang, int rpp, int page, long sinceId, ref string content)
575 Dictionary<string, string> param = new Dictionary<string, string>();
576 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
577 param.Add("include_entities", "1");
578 param.Add("contributor_details", "true");
579 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
580 if (rpp > 0) param.Add("rpp", rpp.ToString());
581 if (page > 0) param.Add("page", page.ToString());
582 if (sinceId > 0) param.Add("since_id", sinceId.ToString());
584 if (param.Count == 0) return HttpStatusCode.BadRequest;
586 return httpConVar.GetContent(GetMethod,
587 CreateTwitterUri("/phoenix_search.phoenix"),
591 MyCommon.GetAssemblyName());
594 public HttpStatusCode Search(string words, string lang, int rpp, int page, long sinceId, ref string content)
596 Dictionary<string, string> param = new Dictionary<string, string>();
597 if (!string.IsNullOrEmpty(words)) param.Add("q", words);
598 if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang);
599 if (rpp > 0) param.Add("rpp", rpp.ToString());
600 if (page > 0) param.Add("page", page.ToString());
601 if (sinceId > 0) param.Add("since_id", sinceId.ToString());
603 if (param.Count == 0) return HttpStatusCode.BadRequest;
605 param.Add("result_type", "recent");
606 param.Add("include_entities", "true");
607 return httpConVar.GetContent(GetMethod,
608 this.CreateTwitterSearchUri("/search.json"),
612 MyCommon.GetAssemblyName());
615 public HttpStatusCode SavedSearches(ref string content)
617 return httpCon.GetContent(GetMethod,
618 CreateTwitterUri("/1/saved_searches.json"),
625 public HttpStatusCode FollowerIds(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/followers/ids.json"),
634 this.apiStatusHeaders,
638 public HttpStatusCode NoRetweetIds(long cursor, ref string content)
640 Dictionary<string, string> param = new Dictionary<string, string>();
641 param.Add("cursor", cursor.ToString());
643 return httpCon.GetContent(GetMethod,
644 CreateTwitterUri("/1/friendships/no_retweet_ids.json"),
647 this.apiStatusHeaders,
651 public HttpStatusCode RateLimitStatus(ref string content)
653 return httpCon.GetContent(GetMethod,
654 CreateTwitterUri("/1/account/rate_limit_status.json"),
657 this.apiStatusHeaders,
662 public HttpStatusCode GetLists(string user, long cursor, ref string content)
664 Dictionary<string, string> param = new Dictionary<string, string>();
665 param.Add("screen_name", user);
666 param.Add("cursor", cursor.ToString());
667 return httpCon.GetContent(GetMethod,
668 CreateTwitterUri("/1/lists.json"),
671 this.apiStatusHeaders,
675 public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
677 string mode = "public";
681 Dictionary<string, string> param = new Dictionary<string, string>();
682 param.Add("screen_name", user);
683 param.Add("list_id", list_id);
684 if (name != null) param.Add("name", name);
685 if (mode != null) param.Add("mode", mode);
686 if (description != null) param.Add("description", description);
688 return httpCon.GetContent(PostMethod,
689 CreateTwitterUri("/1/lists/update.json"),
696 public HttpStatusCode DeleteListID(string user, string list_id, ref string content)
698 Dictionary<string, string> param = new Dictionary<string, string>();
699 param.Add("screen_name", user);
700 param.Add("list_id", list_id);
702 return httpCon.GetContent(PostMethod,
703 CreateTwitterUri("/1/lists/destroy.json"),
710 public HttpStatusCode GetListsSubscriptions(string user, long cursor, ref string content)
712 Dictionary<string, string> param = new Dictionary<string, string>();
713 param.Add("screen_name", user);
714 param.Add("cursor", cursor.ToString());
715 return httpCon.GetContent(GetMethod,
716 CreateTwitterUri("/1/lists/subscriptions.json"),
719 this.apiStatusHeaders,
723 public HttpStatusCode GetListsStatuses(long userId, long list_id, int per_page, long max_id, long since_id, Boolean isRTinclude, ref string content)
725 //認証なくても取得できるが、protectedユーザー分が抜ける
726 Dictionary<string, string> param = new Dictionary<string, string>();
727 param.Add("user_id", userId.ToString());
728 param.Add("list_id", list_id.ToString());
730 param.Add("include_rts", "true");
732 param.Add("per_page", per_page.ToString());
734 param.Add("max_id", max_id.ToString());
736 param.Add("since_id", since_id.ToString());
737 param.Add("include_entities", "true");
739 return httpCon.GetContent(GetMethod,
740 CreateTwitterUri("/1/lists/statuses.json"),
743 this.apiStatusHeaders,
747 public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
749 string mode = "public";
753 Dictionary<string, string> param = new Dictionary<string, string>();
754 param.Add("name", listname);
755 param.Add("mode", mode);
756 if (!string.IsNullOrEmpty(description))
757 param.Add("description", description);
759 return httpCon.GetContent(PostMethod,
760 CreateTwitterUri("/1/lists/create.json"),
767 public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content)
769 Dictionary<string, string> param = new Dictionary<string, string>();
770 param.Add("screen_name", user);
771 param.Add("list_id", list_id);
772 param.Add("cursor", cursor.ToString());
773 return httpCon.GetContent(GetMethod,
774 CreateTwitterUri("/1/lists/members.json"),
777 this.apiStatusHeaders,
781 public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content)
783 Dictionary<string, string> param = new Dictionary<string, string>();
784 param.Add("list_id", list_id);
785 param.Add("screen_name", memberName);
786 return httpCon.GetContent(PostMethod,
787 CreateTwitterUri("/1/lists/members/create.json"),
794 //public HttpStatusCode CreateListMembers(string user, string list_id, string memberName, ref string content)
796 // //正常に動かないので旧APIで様子見
797 // //Dictionary<string, string> param = new Dictionary<string, string>();
798 // //param.Add("screen_name", user)
799 // //param.Add("list_id", list_id)
800 // //param.Add("member_screen_name", memberName)
801 // //return httpCon.GetContent(PostMethod,
802 // // CreateTwitterUri("/1/lists/members/create.json"),
807 // Dictionary<string, string> param = new Dictionary<string, string>();
808 // param.Add("id", memberName)
809 // return httpCon.GetContent(PostMethod,
810 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
817 public HttpStatusCode DeleteListMembers(string list_id, string memberName, ref string content)
819 Dictionary<string, string> param = new Dictionary<string, string>();
820 param.Add("screen_name", memberName);
821 param.Add("list_id", list_id);
822 return httpCon.GetContent(PostMethod,
823 CreateTwitterUri("/1/lists/members/destroy.json"),
830 //public HttpStatusCode DeleteListMembers(string user, string list_id, string memberName, ref string content)
832 // //Dictionary<string, string> param = new Dictionary<string, string>();
833 // //param.Add("screen_name", user)
834 // //param.Add("list_id", list_id)
835 // //param.Add("member_screen_name", memberName)
836 // //return httpCon.GetContent(PostMethod,
837 // // CreateTwitterUri("/1/lists/members/destroy.json"),
842 // Dictionary<string, string> param = new Dictionary<string, string>();
843 // param.Add("id", memberName)
844 // param.Add("_method", "DELETE")
845 // return httpCon.GetContent(PostMethod,
846 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members.json"),
853 public HttpStatusCode ShowListMember(string list_id, string memberName, ref string content)
855 //新APIがmember_screen_nameもmember_user_idも無視して、自分のIDを返してくる。
856 //正式にドキュメントに反映されるまで旧APIを使用する
857 Dictionary<string, string> param = new Dictionary<string, string>();
858 param.Add("screen_name", memberName);
859 param.Add("list_id", list_id);
860 return httpCon.GetContent(GetMethod,
861 CreateTwitterUri("/1/lists/members/show.json"),
864 this.apiStatusHeaders,
866 //return httpCon.GetContent(GetMethod,
867 // CreateTwitterUri("/1/" + user + "/" + list_id + "/members/" + id + ".json"),
870 // MyCommon.TwitterApiInfo.HttpHeaders,
875 public HttpStatusCode Statusid_retweeted_by_ids(long statusid, int count, int page, ref string content)
877 Dictionary<string, string> param = new Dictionary<string, string>();
879 param.Add("count", count.ToString());
881 param.Add("page", page.ToString());
883 return httpCon.GetContent(GetMethod,
884 CreateTwitterUri("/1/statuses/" + statusid.ToString()+ "/retweeted_by/ids.json"),
887 this.apiStatusHeaders,
891 public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content)
893 Dictionary<string, string> param = new Dictionary<string, string>();
895 param.Add("name", name);
896 param.Add("url", url);
897 param.Add("location", location);
898 param.Add("description", description);
899 param.Add("include_entities", "true");
901 return httpCon.GetContent(PostMethod,
902 CreateTwitterUri("/1/account/update_profile.json"),
909 public HttpStatusCode UpdateProfileImage(FileInfo imageFile, ref string content)
911 List<KeyValuePair<string, FileInfo>> binary = new List<KeyValuePair<string, FileInfo>>();
912 binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile));
914 return httpCon.GetContent(PostMethod,
915 CreateTwitterUri("/1/account/update_profile_image.json"),
923 public HttpStatusCode GetRelatedResults(long id, ref string content)
925 //認証なくても取得できるが、protectedユーザー分が抜ける
926 Dictionary<string, string> param = new Dictionary<string, string>();
928 param.Add("include_entities", "true");
930 return httpCon.GetContent(GetMethod,
931 CreateTwitterUri("/1/related_results/show/" + id.ToString()+ ".json"),
934 this.apiStatusHeaders,
938 public HttpStatusCode GetBlockUserIds(ref string content)
940 return httpCon.GetContent(GetMethod,
941 CreateTwitterUri("/1/blocks/blocking/ids.json"),
944 this.apiStatusHeaders,
948 public HttpStatusCode GetConfiguration(ref string content)
950 return httpCon.GetContent(GetMethod,
951 CreateTwitterUri("/1/help/configuration.json"),
954 this.apiStatusHeaders,
958 public HttpStatusCode VerifyCredentials(ref string content)
960 return httpCon.GetContent(GetMethod,
961 CreateTwitterUri("/1/account/verify_credentials.json"),
964 this.apiStatusHeaders,
969 private static string _twitterUrl = "api.twitter.com";
970 private static string _TwitterSearchUrl = "search.twitter.com";
971 private static string _twitterUserStreamUrl = "userstream.twitter.com";
972 private static string _twitterStreamUrl = "stream.twitter.com";
974 private Uri CreateTwitterUri(string path)
976 return new Uri(string.Format("{0}{1}{2}", _protocol, _twitterUrl, path));
979 private Uri CreateTwitterSearchUri(string path)
981 return new Uri(string.Format("{0}{1}{2}", _protocol, _TwitterSearchUrl, path));
984 private Uri CreateTwitterUserStreamUri(string path)
986 return new Uri(string.Format("{0}{1}{2}", "https://", _twitterUserStreamUrl, path));
989 private Uri CreateTwitterStreamUri(string path)
991 return new Uri(string.Format("{0}{1}{2}", "http://", _twitterStreamUrl, path));
994 public static string TwitterUrl
999 HttpOAuthApiProxy.ProxyHost = value;
1003 public static string TwitterSearchUrl
1007 _TwitterSearchUrl = value;
1012 private void GetApiCallback(Object sender, ref HttpStatusCode code, ref string content)
1014 if (code < HttpStatusCode.InternalServerError)
1015 MyCommon.TwitterApiInfo.UpdateFromHeader(this.apiStatusHeaders);
1018 public HttpStatusCode UserStream(ref Stream content,
1023 Dictionary<string, string> param = new Dictionary<string, string>();
1026 param.Add("replies", "all");
1028 if (!string.IsNullOrEmpty(trackwords))
1029 param.Add("track", trackwords);
1031 return httpCon.GetContent(GetMethod,
1032 CreateTwitterUserStreamUri("/2/user.json"),
1038 public HttpStatusCode FilterStream(ref Stream content,
1042 //文中の日本語キーワードに反応せず、使えない(スペースで分かち書きしてないと反応しない)
1043 Dictionary<string, string> param = new Dictionary<string, string>();
1045 if (!string.IsNullOrEmpty(trackwords))
1046 param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray())));
1048 return httpCon.GetContent(PostMethod,
1049 CreateTwitterStreamUri("/1/statuses/filter.json"),
1055 public void RequestAbort()
1057 httpCon.RequestAbort();
1060 public object Clone()
1062 HttpTwitter myCopy = new HttpTwitter();
1063 myCopy.Initialize(this.AccessToken, this.AccessTokenSecret, this.AuthenticatedUsername, this.AuthenticatedUserId);