dev
Revision | fba39b3cd0b3473de1ab22d7aace32fb15a25ef0 (tree) |
---|---|
Time | 2013-04-17 05:29:00 |
Author | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
API v1.1 に対応
ステータスバーの API レートリミット表示をクリックすると API v1 と API v1.1 を
切り替えることができます。
@@ -83,7 +83,7 @@ namespace OpenTween.Api | ||
83 | 83 | [TestCaseSource("ParseRateLimit_TestCase")] |
84 | 84 | public void ParseRateLimitTest(IDictionary<string, string> header, ApiLimit expect) |
85 | 85 | { |
86 | - var limit = TwitterApiStatus.ParseRateLimit(header); | |
86 | + var limit = TwitterApiStatus.ParseRateLimit(header, "X-RateLimit"); | |
87 | 87 | Assert.That(limit, Is.EqualTo(expect)); |
88 | 88 | } |
89 | 89 |
@@ -116,7 +116,7 @@ namespace OpenTween.Api | ||
116 | 116 | [TestCaseSource("ParseMediaRateLimit_TestCase")] |
117 | 117 | public void ParseMediaRateLimitTest(IDictionary<string, string> header, ApiLimit expect) |
118 | 118 | { |
119 | - var limit = TwitterApiStatus.ParseMediaRateLimit(header); | |
119 | + var limit = TwitterApiStatus.ParseRateLimit(header, "X-MediaRateLimit-"); | |
120 | 120 | Assert.That(limit, Is.EqualTo(expect)); |
121 | 121 | } |
122 | 122 |
@@ -146,7 +146,7 @@ namespace OpenTween.Api | ||
146 | 146 | [TestCaseSource("ParseAccessLevel_TestCase")] |
147 | 147 | public void ParseAccessLevelTest(IDictionary<string, string> header, TwitterApiAccessLevel? expect) |
148 | 148 | { |
149 | - var accessLevel = TwitterApiStatus.ParseAccessLevel(header); | |
149 | + var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level"); | |
150 | 150 | Assert.That(accessLevel, Is.EqualTo(expect)); |
151 | 151 | } |
152 | 152 |
@@ -60,24 +60,24 @@ namespace OpenTween.Api | ||
60 | 60 | |
61 | 61 | public void UpdateFromHeader(IDictionary<string, string> header) |
62 | 62 | { |
63 | - var rateLimit = TwitterApiStatus.ParseRateLimit(header); | |
63 | + var rateLimit = TwitterApiStatus.ParseRateLimit(header, "X-RateLimit-"); | |
64 | 64 | if (rateLimit != null) |
65 | 65 | this.AccessLimit = rateLimit; |
66 | 66 | |
67 | - var mediaLimit = TwitterApiStatus.ParseMediaRateLimit(header); | |
67 | + var mediaLimit = TwitterApiStatus.ParseRateLimit(header, "X-MediaRateLimit-"); | |
68 | 68 | if (mediaLimit != null) |
69 | 69 | this.MediaUploadLimit = mediaLimit; |
70 | 70 | |
71 | - var accessLevel = TwitterApiStatus.ParseAccessLevel(header); | |
71 | + var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level"); | |
72 | 72 | if (accessLevel.HasValue) |
73 | 73 | this.AccessLevel = accessLevel.Value; |
74 | 74 | } |
75 | 75 | |
76 | - internal static ApiLimit ParseRateLimit(IDictionary<string, string> header) | |
76 | + internal static ApiLimit ParseRateLimit(IDictionary<string, string> header, string prefix) | |
77 | 77 | { |
78 | - var limitCount = ParseHeaderValue(header, "X-RateLimit-Limit") ?? -1; | |
79 | - var limitRemain = ParseHeaderValue(header, "X-RateLimit-Remaining") ?? -1; | |
80 | - var limitReset = ParseHeaderValue(header, "X-RateLimit-Reset") ?? -1; | |
78 | + var limitCount = ParseHeaderValue(header, prefix + "Limit") ?? -1; | |
79 | + var limitRemain = ParseHeaderValue(header, prefix + "Remaining") ?? -1; | |
80 | + var limitReset = ParseHeaderValue(header, prefix + "Reset") ?? -1; | |
81 | 81 | |
82 | 82 | if (limitCount == -1 || limitRemain == -1 || limitReset == -1) |
83 | 83 | return null; |
@@ -86,25 +86,12 @@ namespace OpenTween.Api | ||
86 | 86 | return new ApiLimit(limitCount, limitRemain, limitResetDate); |
87 | 87 | } |
88 | 88 | |
89 | - internal static ApiLimit ParseMediaRateLimit(IDictionary<string, string> header) | |
89 | + internal static TwitterApiAccessLevel? ParseAccessLevel(IDictionary<string, string> header, string headerName) | |
90 | 90 | { |
91 | - var limitCount = ParseHeaderValue(header, "X-MediaRateLimit-Limit") ?? -1; | |
92 | - var limitRemain = ParseHeaderValue(header, "X-MediaRateLimit-Remaining") ?? -1; | |
93 | - var limitReset = ParseHeaderValue(header, "X-MediaRateLimit-Reset") ?? -1; | |
94 | - | |
95 | - if (limitCount == -1 || limitRemain == -1 || limitReset == -1) | |
96 | - return null; | |
97 | - | |
98 | - var limitResetDate = UnixEpoch.AddSeconds(limitReset).ToLocalTime(); | |
99 | - return new ApiLimit(limitCount, limitRemain, limitResetDate); | |
100 | - } | |
101 | - | |
102 | - internal static TwitterApiAccessLevel? ParseAccessLevel(IDictionary<string, string> header) | |
103 | - { | |
104 | - if (!header.ContainsKey("X-Access-Level")) | |
91 | + if (!header.ContainsKey(headerName)) | |
105 | 92 | return null; |
106 | 93 | |
107 | - switch (header["X-Access-Level"]) | |
94 | + switch (header[headerName]) | |
108 | 95 | { |
109 | 96 | case "read-write-directmessages": |
110 | 97 | case "read-write-privatemessages": |
@@ -117,7 +104,7 @@ namespace OpenTween.Api | ||
117 | 104 | // たまに出てくる空文字列は無視する |
118 | 105 | return null; |
119 | 106 | default: |
120 | - MyCommon.TraceOut("Unknown ApiAccessLevel:" + header["X-Access-Level"]); | |
107 | + MyCommon.TraceOut("Unknown ApiAccessLevel:" + header[headerName]); | |
121 | 108 | return TwitterApiAccessLevel.ReadWriteAndDirectMessage; |
122 | 109 | } |
123 | 110 | } |
@@ -0,0 +1,113 @@ | ||
1 | +// OpenTween - Client of Twitter | |
2 | +// Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/> | |
3 | +// All rights reserved. | |
4 | +// | |
5 | +// This file is part of OpenTween. | |
6 | +// | |
7 | +// This program is free software; you can redistribute it and/or modify it | |
8 | +// under the terms of the GNU General Public License as published by the Free | |
9 | +// Software Foundation; either version 3 of the License, or (at your option) | |
10 | +// any later version. | |
11 | +// | |
12 | +// This program is distributed in the hope that it will be useful, but | |
13 | +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
14 | +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | +// for more details. | |
16 | +// | |
17 | +// You should have received a copy of the GNU General Public License along | |
18 | +// with this program. If not, see <http://www.gnu.org/licenses/>, or write to | |
19 | +// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, | |
20 | +// Boston, MA 02110-1301, USA. | |
21 | + | |
22 | +using System; | |
23 | +using System.Collections.Generic; | |
24 | +using System.Linq; | |
25 | +using System.Text; | |
26 | + | |
27 | +namespace OpenTween.Api | |
28 | +{ | |
29 | + public class TwitterApiStatus11 | |
30 | + { | |
31 | + public TwitterApiAccessLevel AccessLevel { get; set; } | |
32 | + public EndpointLimits AccessLimit { get; private set; } | |
33 | + public ApiLimit MediaUploadLimit { get; set; } | |
34 | + | |
35 | + public class AccessLimitUpdatedEventArgs : EventArgs | |
36 | + { | |
37 | + public readonly string EndpointName; | |
38 | + | |
39 | + public AccessLimitUpdatedEventArgs(string endpointName) | |
40 | + { | |
41 | + this.EndpointName = endpointName; | |
42 | + } | |
43 | + } | |
44 | + public event EventHandler<AccessLimitUpdatedEventArgs> AccessLimitUpdated; | |
45 | + | |
46 | + public TwitterApiStatus11() | |
47 | + { | |
48 | + this.AccessLimit = new EndpointLimits(this); | |
49 | + } | |
50 | + | |
51 | + public void Reset() | |
52 | + { | |
53 | + this.AccessLevel = TwitterApiAccessLevel.Anonymous; | |
54 | + this.AccessLimit.Clear(); | |
55 | + this.MediaUploadLimit = null; | |
56 | + } | |
57 | + | |
58 | + public void UpdateFromHeader(IDictionary<string, string> header, string endpointName) | |
59 | + { | |
60 | + var rateLimit = TwitterApiStatus.ParseRateLimit(header, "X-Rate-Limit-"); | |
61 | + if (rateLimit != null) | |
62 | + this.AccessLimit[endpointName] = rateLimit; | |
63 | + | |
64 | + var mediaLimit = TwitterApiStatus.ParseRateLimit(header, "X-MediaRateLimit-"); | |
65 | + if (mediaLimit != null) | |
66 | + this.MediaUploadLimit = mediaLimit; | |
67 | + | |
68 | + var accessLevel = TwitterApiStatus.ParseAccessLevel(header, "X-Access-Level"); | |
69 | + if (accessLevel.HasValue) | |
70 | + this.AccessLevel = accessLevel.Value; | |
71 | + } | |
72 | + | |
73 | + protected virtual void OnAccessLimitUpdated(AccessLimitUpdatedEventArgs e) | |
74 | + { | |
75 | + if (this.AccessLimitUpdated != null) | |
76 | + this.AccessLimitUpdated(this, e); | |
77 | + } | |
78 | + | |
79 | + public class EndpointLimits | |
80 | + { | |
81 | + public readonly TwitterApiStatus11 Owner; | |
82 | + | |
83 | + private Dictionary<string, ApiLimit> innerDict = new Dictionary<string, ApiLimit>(); | |
84 | + | |
85 | + public EndpointLimits(TwitterApiStatus11 owner) | |
86 | + { | |
87 | + this.Owner = owner; | |
88 | + } | |
89 | + | |
90 | + public ApiLimit this[string endpoint] | |
91 | + { | |
92 | + get | |
93 | + { | |
94 | + if (this.innerDict.ContainsKey(endpoint)) | |
95 | + return this.innerDict[endpoint]; | |
96 | + | |
97 | + return null; | |
98 | + } | |
99 | + set | |
100 | + { | |
101 | + this.innerDict[endpoint] = value; | |
102 | + this.Owner.OnAccessLimitUpdated(new AccessLimitUpdatedEventArgs(endpoint)); | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + public void Clear() | |
107 | + { | |
108 | + this.innerDict.Clear(); | |
109 | + this.Owner.OnAccessLimitUpdated(new AccessLimitUpdatedEventArgs(null)); | |
110 | + } | |
111 | + } | |
112 | + } | |
113 | +} |
@@ -35,6 +35,15 @@ namespace OpenTween | ||
35 | 35 | { |
36 | 36 | public class HttpTwitter : ICloneable |
37 | 37 | { |
38 | + /// <summary> | |
39 | + /// API v1.1 を有効にする否か | |
40 | + /// </summary> | |
41 | + /// <remarks> | |
42 | + /// 旧APIが使用出来なくなったら消す予定。 | |
43 | + /// 静的フィールドとしているのは TwitterUserstream クラスが Clone メソッドを使用しているため | |
44 | + /// </remarks> | |
45 | + public static bool API11Enabled { get; set; } | |
46 | + | |
38 | 47 | //OAuth関連 |
39 | 48 | ///<summary> |
40 | 49 | ///OAuthのアクセストークン取得先URI |
@@ -71,11 +80,19 @@ namespace OpenTween | ||
71 | 80 | {"X-RateLimit-Limit", ""}, |
72 | 81 | {"X-RateLimit-Remaining", ""}, |
73 | 82 | {"X-RateLimit-Reset", ""}, |
83 | + {"X-Rate-Limit-Limit", ""}, | |
84 | + {"X-Rate-Limit-Remaining", ""}, | |
85 | + {"X-Rate-Limit-Reset", ""}, | |
74 | 86 | {"X-MediaRateLimit-Limit", ""}, |
75 | 87 | {"X-MediaRateLimit-Remaining", ""}, |
76 | 88 | {"X-MediaRateLimit-Reset", ""}, |
77 | 89 | }; |
78 | 90 | |
91 | + static HttpTwitter() | |
92 | + { | |
93 | + HttpTwitter.API11Enabled = true; | |
94 | + } | |
95 | + | |
79 | 96 | public void Initialize(string accessToken, |
80 | 97 | string accessTokenSecret, |
81 | 98 | string username, |
@@ -197,11 +214,11 @@ namespace OpenTween | ||
197 | 214 | //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true") |
198 | 215 | |
199 | 216 | return httpCon.GetContent(PostMethod, |
200 | - CreateTwitterUri("/1/statuses/update.json"), | |
201 | - param, | |
202 | - ref content, | |
203 | - null, | |
204 | - null); | |
217 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/update.json" : "/1/statuses/update.json"), | |
218 | + param, | |
219 | + ref content, | |
220 | + null, | |
221 | + null); | |
205 | 222 | } |
206 | 223 | |
207 | 224 | public HttpStatusCode UpdateStatusWithMedia(string status, long replyToId, FileInfo mediaFile, ref string content) |
@@ -217,24 +234,28 @@ namespace OpenTween | ||
217 | 234 | binary.Add(new KeyValuePair<string, FileInfo>("media[]", mediaFile)); |
218 | 235 | |
219 | 236 | return httpCon.GetContent(PostMethod, |
220 | - new Uri("https://upload.twitter.com/1/statuses/update_with_media.json"), | |
221 | - param, | |
222 | - binary, | |
223 | - ref content, | |
224 | - this.apiStatusHeaders, | |
225 | - GetApiCallback); | |
237 | + HttpTwitter.API11Enabled ? CreateTwitterUri("/1.1/statuses/update_with_media.json") : new Uri("https://upload.twitter.com/1/statuses/update_with_media.json"), | |
238 | + param, | |
239 | + binary, | |
240 | + ref content, | |
241 | + this.apiStatusHeaders, | |
242 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/update_with_media") : GetApiCallback); | |
226 | 243 | } |
227 | 244 | |
228 | 245 | public HttpStatusCode DestroyStatus(long id) |
229 | 246 | { |
230 | 247 | string content = null; |
231 | 248 | |
249 | + var param = new Dictionary<string, string>(); | |
250 | + if (HttpTwitter.API11Enabled) | |
251 | + param.Add("id", id.ToString()); | |
252 | + | |
232 | 253 | return httpCon.GetContent(PostMethod, |
233 | - CreateTwitterUri("/1/statuses/destroy/" + id.ToString()+ ".json"), | |
234 | - null, | |
235 | - ref content, | |
236 | - null, | |
237 | - null); | |
254 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/destroy.json" : "/1/statuses/destroy/" + id + ".json"), | |
255 | + param, | |
256 | + ref content, | |
257 | + null, | |
258 | + null); | |
238 | 259 | } |
239 | 260 | |
240 | 261 | public HttpStatusCode SendDirectMessage(string status, string sendto, ref string content) |
@@ -245,23 +266,27 @@ namespace OpenTween | ||
245 | 266 | //if (AppendSettingDialog.Instance.ShortenTco && AppendSettingDialog.Instance.UrlConvertAuto) param.Add("wrap_links", "true") |
246 | 267 | |
247 | 268 | return httpCon.GetContent(PostMethod, |
248 | - CreateTwitterUri("/1/direct_messages/new.json"), | |
249 | - param, | |
250 | - ref content, | |
251 | - null, | |
252 | - null); | |
269 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/new.json" : "/1/direct_messages/new.json"), | |
270 | + param, | |
271 | + ref content, | |
272 | + null, | |
273 | + null); | |
253 | 274 | } |
254 | 275 | |
255 | 276 | public HttpStatusCode DestroyDirectMessage(long id) |
256 | 277 | { |
257 | 278 | string content = null; |
258 | 279 | |
280 | + var param = new Dictionary<string, string>(); | |
281 | + if (HttpTwitter.API11Enabled) | |
282 | + param.Add("id", id.ToString()); | |
283 | + | |
259 | 284 | return httpCon.GetContent(PostMethod, |
260 | - CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString()+ ".json"), | |
261 | - null, | |
262 | - ref content, | |
263 | - null, | |
264 | - null); | |
285 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/destroy.json" : "/1/direct_messages/destroy/" + id + ".json"), | |
286 | + param, | |
287 | + ref content, | |
288 | + null, | |
289 | + null); | |
265 | 290 | } |
266 | 291 | |
267 | 292 | public HttpStatusCode RetweetStatus(long id, ref string content) |
@@ -270,11 +295,11 @@ namespace OpenTween | ||
270 | 295 | param.Add("include_entities", "true"); |
271 | 296 | |
272 | 297 | return httpCon.GetContent(PostMethod, |
273 | - CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".json"), | |
274 | - param, | |
275 | - ref content, | |
276 | - null, | |
277 | - null); | |
298 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/retweet/" + id + ".json" : "/1/statuses/retweet/" + id + ".json"), | |
299 | + param, | |
300 | + ref content, | |
301 | + null, | |
302 | + null); | |
278 | 303 | } |
279 | 304 | |
280 | 305 | public HttpStatusCode ShowUserInfo(string screenName, ref string content) |
@@ -283,11 +308,11 @@ namespace OpenTween | ||
283 | 308 | param.Add("screen_name", screenName); |
284 | 309 | param.Add("include_entities", "true"); |
285 | 310 | return httpCon.GetContent(GetMethod, |
286 | - CreateTwitterUri("/1/users/show.json"), | |
287 | - param, | |
288 | - ref content, | |
289 | - this.apiStatusHeaders, | |
290 | - GetApiCallback); | |
311 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/users/show.json" : "/1/users/show.json"), | |
312 | + param, | |
313 | + ref content, | |
314 | + this.apiStatusHeaders, | |
315 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/users/show/:id") : GetApiCallback); | |
291 | 316 | } |
292 | 317 | |
293 | 318 | public HttpStatusCode CreateFriendships(string screenName, ref string content) |
@@ -296,11 +321,11 @@ namespace OpenTween | ||
296 | 321 | param.Add("screen_name", screenName); |
297 | 322 | |
298 | 323 | return httpCon.GetContent(PostMethod, |
299 | - CreateTwitterUri("/1/friendships/create.json"), | |
300 | - param, | |
301 | - ref content, | |
302 | - null, | |
303 | - null); | |
324 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/create.json" : "/1/friendships/create.json"), | |
325 | + param, | |
326 | + ref content, | |
327 | + null, | |
328 | + null); | |
304 | 329 | } |
305 | 330 | |
306 | 331 | public HttpStatusCode DestroyFriendships(string screenName, ref string content) |
@@ -309,11 +334,11 @@ namespace OpenTween | ||
309 | 334 | param.Add("screen_name", screenName); |
310 | 335 | |
311 | 336 | return httpCon.GetContent(PostMethod, |
312 | - CreateTwitterUri("/1/friendships/destroy.json"), | |
313 | - param, | |
314 | - ref content, | |
315 | - null, | |
316 | - null); | |
337 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/destroy.json" : "/1/friendships/destroy.json"), | |
338 | + param, | |
339 | + ref content, | |
340 | + null, | |
341 | + null); | |
317 | 342 | } |
318 | 343 | |
319 | 344 | public HttpStatusCode CreateBlock(string screenName, ref string content) |
@@ -322,11 +347,11 @@ namespace OpenTween | ||
322 | 347 | param.Add("screen_name", screenName); |
323 | 348 | |
324 | 349 | return httpCon.GetContent(PostMethod, |
325 | - CreateTwitterUri("/1/blocks/create.json"), | |
326 | - param, | |
327 | - ref content, | |
328 | - null, | |
329 | - null); | |
350 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/create.json" : "/1/blocks/create.json"), | |
351 | + param, | |
352 | + ref content, | |
353 | + null, | |
354 | + null); | |
330 | 355 | } |
331 | 356 | |
332 | 357 | public HttpStatusCode DestroyBlock(string screenName, ref string content) |
@@ -335,11 +360,11 @@ namespace OpenTween | ||
335 | 360 | param.Add("screen_name", screenName); |
336 | 361 | |
337 | 362 | return httpCon.GetContent(PostMethod, |
338 | - CreateTwitterUri("/1/blocks/destroy.json"), | |
339 | - param, | |
340 | - ref content, | |
341 | - null, | |
342 | - null); | |
363 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/destroy.json" : "/1/blocks/destroy.json"), | |
364 | + param, | |
365 | + ref content, | |
366 | + null, | |
367 | + null); | |
343 | 368 | } |
344 | 369 | |
345 | 370 | public HttpStatusCode ReportSpam(string screenName, ref string content) |
@@ -348,11 +373,11 @@ namespace OpenTween | ||
348 | 373 | param.Add("screen_name", screenName); |
349 | 374 | |
350 | 375 | return httpCon.GetContent(PostMethod, |
351 | - CreateTwitterUri("/1/report_spam.json"), | |
352 | - param, | |
353 | - ref content, | |
354 | - null, | |
355 | - null); | |
376 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/users/report_spam.json" : "/1/report_spam.json"), | |
377 | + param, | |
378 | + ref content, | |
379 | + null, | |
380 | + null); | |
356 | 381 | } |
357 | 382 | |
358 | 383 | public HttpStatusCode ShowFriendships(string souceScreenName, string targetScreenName, ref string content) |
@@ -362,11 +387,11 @@ namespace OpenTween | ||
362 | 387 | param.Add("target_screen_name", targetScreenName); |
363 | 388 | |
364 | 389 | return httpCon.GetContent(GetMethod, |
365 | - CreateTwitterUri("/1/friendships/show.json"), | |
366 | - param, | |
367 | - ref content, | |
368 | - this.apiStatusHeaders, | |
369 | - GetApiCallback); | |
390 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/show.json" : "/1/friendships/show.json"), | |
391 | + param, | |
392 | + ref content, | |
393 | + this.apiStatusHeaders, | |
394 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/show") : GetApiCallback); | |
370 | 395 | } |
371 | 396 | |
372 | 397 | public HttpStatusCode ShowStatuses(long id, ref string content) |
@@ -374,31 +399,39 @@ namespace OpenTween | ||
374 | 399 | Dictionary<string, string> param = new Dictionary<string, string>(); |
375 | 400 | param.Add("include_entities", "true"); |
376 | 401 | return httpCon.GetContent(GetMethod, |
377 | - CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".json"), | |
378 | - param, | |
379 | - ref content, | |
380 | - this.apiStatusHeaders, | |
381 | - GetApiCallback); | |
402 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/show/" + id + ".json" : "/1/statuses/show/" + id + ".json"), | |
403 | + param, | |
404 | + ref content, | |
405 | + this.apiStatusHeaders, | |
406 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/show/:id") : GetApiCallback); | |
382 | 407 | } |
383 | 408 | |
384 | 409 | public HttpStatusCode CreateFavorites(long id, ref string content) |
385 | 410 | { |
411 | + var param = new Dictionary<string, string>(); | |
412 | + if (HttpTwitter.API11Enabled) | |
413 | + param.Add("id", id.ToString()); | |
414 | + | |
386 | 415 | return httpCon.GetContent(PostMethod, |
387 | - CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".json"), | |
388 | - null, | |
389 | - ref content, | |
390 | - null, | |
391 | - null); | |
416 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/create.json" : "/1/favorites/create/" + id + ".json"), | |
417 | + param, | |
418 | + ref content, | |
419 | + null, | |
420 | + null); | |
392 | 421 | } |
393 | 422 | |
394 | 423 | public HttpStatusCode DestroyFavorites(long id, ref string content) |
395 | 424 | { |
425 | + var param = new Dictionary<string, string>(); | |
426 | + if (HttpTwitter.API11Enabled) | |
427 | + param.Add("id", id.ToString()); | |
428 | + | |
396 | 429 | return httpCon.GetContent(PostMethod, |
397 | - CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".json"), | |
398 | - null, | |
399 | - ref content, | |
400 | - null, | |
401 | - null); | |
430 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/destroy.json" : "/1/favorites/destroy/" + id + ".json"), | |
431 | + null, | |
432 | + ref content, | |
433 | + null, | |
434 | + null); | |
402 | 435 | } |
403 | 436 | |
404 | 437 | public HttpStatusCode HomeTimeline(int count, long max_id, long since_id, ref string content) |
@@ -414,11 +447,11 @@ namespace OpenTween | ||
414 | 447 | param.Add("include_entities", "true"); |
415 | 448 | |
416 | 449 | return httpCon.GetContent(GetMethod, |
417 | - CreateTwitterUri("/1/statuses/home_timeline.json"), | |
418 | - param, | |
419 | - ref content, | |
420 | - this.apiStatusHeaders, | |
421 | - GetApiCallback); | |
450 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/home_timeline.json" : "/1/statuses/home_timeline.json"), | |
451 | + param, | |
452 | + ref content, | |
453 | + this.apiStatusHeaders, | |
454 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/home_timeline") : GetApiCallback); | |
422 | 455 | } |
423 | 456 | |
424 | 457 | public HttpStatusCode UserTimeline(long user_id, string screen_name, int count, long max_id, long since_id, ref string content) |
@@ -443,11 +476,11 @@ namespace OpenTween | ||
443 | 476 | param.Add("include_entities", "true"); |
444 | 477 | |
445 | 478 | return httpCon.GetContent(GetMethod, |
446 | - CreateTwitterUri("/1/statuses/user_timeline.json"), | |
447 | - param, | |
448 | - ref content, | |
449 | - this.apiStatusHeaders, | |
450 | - GetApiCallback); | |
479 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/user_timeline.json" : "/1/statuses/user_timeline.json"), | |
480 | + param, | |
481 | + ref content, | |
482 | + this.apiStatusHeaders, | |
483 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/user_timeline") : GetApiCallback); | |
451 | 484 | } |
452 | 485 | |
453 | 486 | public HttpStatusCode PublicTimeline(int count, long max_id, long since_id, ref string content) |
@@ -462,12 +495,14 @@ namespace OpenTween | ||
462 | 495 | |
463 | 496 | param.Add("include_entities", "true"); |
464 | 497 | |
498 | + // TODO: API v1.1 に存在しない API (旧 API で代替) | |
499 | + | |
465 | 500 | return httpCon.GetContent(GetMethod, |
466 | - CreateTwitterUri("/1/statuses/public_timeline.json"), | |
467 | - param, | |
468 | - ref content, | |
469 | - this.apiStatusHeaders, | |
470 | - GetApiCallback); | |
501 | + CreateTwitterUri("/1/statuses/public_timeline.json"), | |
502 | + param, | |
503 | + ref content, | |
504 | + this.apiStatusHeaders, | |
505 | + GetApiCallback); | |
471 | 506 | } |
472 | 507 | |
473 | 508 | public HttpStatusCode Mentions(int count, long max_id, long since_id, ref string content) |
@@ -483,11 +518,11 @@ namespace OpenTween | ||
483 | 518 | param.Add("include_entities", "true"); |
484 | 519 | |
485 | 520 | return httpCon.GetContent(GetMethod, |
486 | - CreateTwitterUri("/1/statuses/mentions.json"), | |
487 | - param, | |
488 | - ref content, | |
489 | - this.apiStatusHeaders, | |
490 | - GetApiCallback); | |
521 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/statuses/mentions_timeline.json" : "/1/statuses/mentions.json"), | |
522 | + param, | |
523 | + ref content, | |
524 | + this.apiStatusHeaders, | |
525 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/statuses/mentions_timeline") : GetApiCallback); | |
491 | 526 | } |
492 | 527 | |
493 | 528 | public HttpStatusCode DirectMessages(int count, long max_id, long since_id, ref string content) |
@@ -502,11 +537,11 @@ namespace OpenTween | ||
502 | 537 | param.Add("include_entities", "true"); |
503 | 538 | |
504 | 539 | return httpCon.GetContent(GetMethod, |
505 | - CreateTwitterUri("/1/direct_messages.json"), | |
506 | - param, | |
507 | - ref content, | |
508 | - this.apiStatusHeaders, | |
509 | - GetApiCallback); | |
540 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages.json" : "/1/direct_messages.json"), | |
541 | + param, | |
542 | + ref content, | |
543 | + this.apiStatusHeaders, | |
544 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages") : GetApiCallback); | |
510 | 545 | } |
511 | 546 | |
512 | 547 | public HttpStatusCode DirectMessagesSent(int count, long max_id, long since_id, ref string content) |
@@ -521,11 +556,11 @@ namespace OpenTween | ||
521 | 556 | param.Add("include_entities", "true"); |
522 | 557 | |
523 | 558 | return httpCon.GetContent(GetMethod, |
524 | - CreateTwitterUri("/1/direct_messages/sent.json"), | |
525 | - param, | |
526 | - ref content, | |
527 | - this.apiStatusHeaders, | |
528 | - GetApiCallback); | |
559 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/direct_messages/sent.json" : "/1/direct_messages/sent.json"), | |
560 | + param, | |
561 | + ref content, | |
562 | + this.apiStatusHeaders, | |
563 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/direct_messages/sent") : GetApiCallback); | |
529 | 564 | } |
530 | 565 | |
531 | 566 | public HttpStatusCode Favorites(int count, int page, ref string content) |
@@ -541,11 +576,11 @@ namespace OpenTween | ||
541 | 576 | param.Add("include_entities", "true"); |
542 | 577 | |
543 | 578 | return httpCon.GetContent(GetMethod, |
544 | - CreateTwitterUri("/1/favorites.json"), | |
545 | - param, | |
546 | - ref content, | |
547 | - this.apiStatusHeaders, | |
548 | - GetApiCallback); | |
579 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/favorites/list.json" : "/1/favorites.json"), | |
580 | + param, | |
581 | + ref content, | |
582 | + this.apiStatusHeaders, | |
583 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/favorites/list") : GetApiCallback); | |
549 | 584 | } |
550 | 585 | |
551 | 586 | public HttpStatusCode PhoenixSearch(string querystr, ref string content) |
@@ -591,12 +626,12 @@ namespace OpenTween | ||
591 | 626 | MyCommon.GetAssemblyName()); |
592 | 627 | } |
593 | 628 | |
594 | - public HttpStatusCode Search(string words, string lang, int rpp, int page, long sinceId, ref string content) | |
629 | + public HttpStatusCode Search(string words, string lang, int count, int page, long sinceId, ref string content) | |
595 | 630 | { |
596 | 631 | Dictionary<string, string> param = new Dictionary<string, string>(); |
597 | 632 | if (!string.IsNullOrEmpty(words)) param.Add("q", words); |
598 | 633 | if (!string.IsNullOrEmpty(lang)) param.Add("lang", lang); |
599 | - if (rpp > 0) param.Add("rpp", rpp.ToString()); | |
634 | + if (count > 0) param.Add(HttpTwitter.API11Enabled ? "count" : "rpp", count.ToString()); | |
600 | 635 | if (page > 0) param.Add("page", page.ToString()); |
601 | 636 | if (sinceId > 0) param.Add("since_id", sinceId.ToString()); |
602 | 637 |
@@ -604,22 +639,22 @@ namespace OpenTween | ||
604 | 639 | |
605 | 640 | param.Add("result_type", "recent"); |
606 | 641 | param.Add("include_entities", "true"); |
607 | - return httpConVar.GetContent(GetMethod, | |
608 | - this.CreateTwitterSearchUri("/search.json"), | |
609 | - param, | |
610 | - out content, | |
611 | - null, | |
612 | - MyCommon.GetAssemblyName()); | |
642 | + return httpCon.GetContent(GetMethod, | |
643 | + HttpTwitter.API11Enabled ? this.CreateTwitterUri("/1.1/search/tweets.json") : this.CreateTwitterSearchUri("/search.json"), | |
644 | + param, | |
645 | + ref content, | |
646 | + null, | |
647 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/search/tweets") : GetApiCallback); | |
613 | 648 | } |
614 | 649 | |
615 | 650 | public HttpStatusCode SavedSearches(ref string content) |
616 | 651 | { |
617 | 652 | return httpCon.GetContent(GetMethod, |
618 | - CreateTwitterUri("/1/saved_searches.json"), | |
619 | - null, | |
620 | - ref content, | |
621 | - null, | |
622 | - GetApiCallback); | |
653 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/saved_searches/list.json" : "/1/saved_searches.json"), | |
654 | + null, | |
655 | + ref content, | |
656 | + null, | |
657 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/saved_searches/list") : GetApiCallback); | |
623 | 658 | } |
624 | 659 | |
625 | 660 | public HttpStatusCode FollowerIds(long cursor, ref string content) |
@@ -628,11 +663,11 @@ namespace OpenTween | ||
628 | 663 | param.Add("cursor", cursor.ToString()); |
629 | 664 | |
630 | 665 | return httpCon.GetContent(GetMethod, |
631 | - CreateTwitterUri("/1/followers/ids.json"), | |
632 | - param, | |
633 | - ref content, | |
634 | - this.apiStatusHeaders, | |
635 | - GetApiCallback); | |
666 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/followers/ids.json" : "/1/followers/ids.json"), | |
667 | + param, | |
668 | + ref content, | |
669 | + this.apiStatusHeaders, | |
670 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/followers/ids") : GetApiCallback); | |
636 | 671 | } |
637 | 672 | |
638 | 673 | public HttpStatusCode NoRetweetIds(long cursor, ref string content) |
@@ -641,21 +676,21 @@ namespace OpenTween | ||
641 | 676 | param.Add("cursor", cursor.ToString()); |
642 | 677 | |
643 | 678 | return httpCon.GetContent(GetMethod, |
644 | - CreateTwitterUri("/1/friendships/no_retweet_ids.json"), | |
645 | - param, | |
646 | - ref content, | |
647 | - this.apiStatusHeaders, | |
648 | - GetApiCallback); | |
679 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/friendships/no_retweets/ids.json" : "/1/friendships/no_retweet_ids.json"), | |
680 | + param, | |
681 | + ref content, | |
682 | + this.apiStatusHeaders, | |
683 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/friendships/no_retweets/ids") : GetApiCallback); | |
649 | 684 | } |
650 | 685 | |
651 | 686 | public HttpStatusCode RateLimitStatus(ref string content) |
652 | 687 | { |
653 | 688 | return httpCon.GetContent(GetMethod, |
654 | - CreateTwitterUri("/1/account/rate_limit_status.json"), | |
655 | - null, | |
656 | - ref content, | |
657 | - this.apiStatusHeaders, | |
658 | - GetApiCallback); | |
689 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/application/rate_limit_status.json" : "/1/account/rate_limit_status.json"), | |
690 | + null, | |
691 | + ref content, | |
692 | + this.apiStatusHeaders, | |
693 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/application/rate_limit_status") : GetApiCallback); | |
659 | 694 | } |
660 | 695 | |
661 | 696 | #region Lists |
@@ -665,11 +700,11 @@ namespace OpenTween | ||
665 | 700 | param.Add("screen_name", user); |
666 | 701 | param.Add("cursor", cursor.ToString()); |
667 | 702 | return httpCon.GetContent(GetMethod, |
668 | - CreateTwitterUri("/1/lists.json"), | |
669 | - param, | |
670 | - ref content, | |
671 | - this.apiStatusHeaders, | |
672 | - GetApiCallback); | |
703 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/list.json" : "/1/lists.json"), | |
704 | + param, | |
705 | + ref content, | |
706 | + this.apiStatusHeaders, | |
707 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/list") : GetApiCallback); | |
673 | 708 | } |
674 | 709 | |
675 | 710 | public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content) |
@@ -686,11 +721,11 @@ namespace OpenTween | ||
686 | 721 | if (description != null) param.Add("description", description); |
687 | 722 | |
688 | 723 | return httpCon.GetContent(PostMethod, |
689 | - CreateTwitterUri("/1/lists/update.json"), | |
690 | - param, | |
691 | - ref content, | |
692 | - null, | |
693 | - null); | |
724 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/update.json" : "/1/lists/update.json"), | |
725 | + param, | |
726 | + ref content, | |
727 | + null, | |
728 | + null); | |
694 | 729 | } |
695 | 730 | |
696 | 731 | public HttpStatusCode DeleteListID(string user, string list_id, ref string content) |
@@ -700,11 +735,11 @@ namespace OpenTween | ||
700 | 735 | param.Add("list_id", list_id); |
701 | 736 | |
702 | 737 | return httpCon.GetContent(PostMethod, |
703 | - CreateTwitterUri("/1/lists/destroy.json"), | |
704 | - param, | |
705 | - ref content, | |
706 | - null, | |
707 | - null); | |
738 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/destroy.json" : "/1/lists/destroy.json"), | |
739 | + param, | |
740 | + ref content, | |
741 | + null, | |
742 | + null); | |
708 | 743 | } |
709 | 744 | |
710 | 745 | public HttpStatusCode GetListsSubscriptions(string user, long cursor, ref string content) |
@@ -713,11 +748,11 @@ namespace OpenTween | ||
713 | 748 | param.Add("screen_name", user); |
714 | 749 | param.Add("cursor", cursor.ToString()); |
715 | 750 | return httpCon.GetContent(GetMethod, |
716 | - CreateTwitterUri("/1/lists/subscriptions.json"), | |
717 | - param, | |
718 | - ref content, | |
719 | - this.apiStatusHeaders, | |
720 | - GetApiCallback); | |
751 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/subscriptions.json" : "/1/lists/subscriptions.json"), | |
752 | + param, | |
753 | + ref content, | |
754 | + this.apiStatusHeaders, | |
755 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/subscriptions") : GetApiCallback); | |
721 | 756 | } |
722 | 757 | |
723 | 758 | public HttpStatusCode GetListsStatuses(long userId, long list_id, int per_page, long max_id, long since_id, Boolean isRTinclude, ref string content) |
@@ -726,8 +761,7 @@ namespace OpenTween | ||
726 | 761 | Dictionary<string, string> param = new Dictionary<string, string>(); |
727 | 762 | param.Add("user_id", userId.ToString()); |
728 | 763 | param.Add("list_id", list_id.ToString()); |
729 | - if (isRTinclude) | |
730 | - param.Add("include_rts", "true"); | |
764 | + param.Add("include_rts", isRTinclude ? "true" : "false"); | |
731 | 765 | if (per_page > 0) |
732 | 766 | param.Add("per_page", per_page.ToString()); |
733 | 767 | if (max_id > 0) |
@@ -737,11 +771,11 @@ namespace OpenTween | ||
737 | 771 | param.Add("include_entities", "true"); |
738 | 772 | |
739 | 773 | return httpCon.GetContent(GetMethod, |
740 | - CreateTwitterUri("/1/lists/statuses.json"), | |
741 | - param, | |
742 | - ref content, | |
743 | - this.apiStatusHeaders, | |
744 | - GetApiCallback); | |
774 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/statuses.json" : "/1/lists/statuses.json"), | |
775 | + param, | |
776 | + ref content, | |
777 | + this.apiStatusHeaders, | |
778 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/statuses") : GetApiCallback); | |
745 | 779 | } |
746 | 780 | |
747 | 781 | public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content) |
@@ -757,11 +791,11 @@ namespace OpenTween | ||
757 | 791 | param.Add("description", description); |
758 | 792 | |
759 | 793 | return httpCon.GetContent(PostMethod, |
760 | - CreateTwitterUri("/1/lists/create.json"), | |
761 | - param, | |
762 | - ref content, | |
763 | - null, | |
764 | - null); | |
794 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/create.json" : "/1/lists/create.json"), | |
795 | + param, | |
796 | + ref content, | |
797 | + null, | |
798 | + null); | |
765 | 799 | } |
766 | 800 | |
767 | 801 | public HttpStatusCode GetListMembers(string user, string list_id, long cursor, ref string content) |
@@ -771,11 +805,11 @@ namespace OpenTween | ||
771 | 805 | param.Add("list_id", list_id); |
772 | 806 | param.Add("cursor", cursor.ToString()); |
773 | 807 | return httpCon.GetContent(GetMethod, |
774 | - CreateTwitterUri("/1/lists/members.json"), | |
775 | - param, | |
776 | - ref content, | |
777 | - this.apiStatusHeaders, | |
778 | - GetApiCallback); | |
808 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members.json" : "/1/lists/members.json"), | |
809 | + param, | |
810 | + ref content, | |
811 | + this.apiStatusHeaders, | |
812 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members") : GetApiCallback); | |
779 | 813 | } |
780 | 814 | |
781 | 815 | public HttpStatusCode CreateListMembers(string list_id, string memberName, ref string content) |
@@ -784,11 +818,11 @@ namespace OpenTween | ||
784 | 818 | param.Add("list_id", list_id); |
785 | 819 | param.Add("screen_name", memberName); |
786 | 820 | return httpCon.GetContent(PostMethod, |
787 | - CreateTwitterUri("/1/lists/members/create.json"), | |
788 | - param, | |
789 | - ref content, | |
790 | - null, | |
791 | - null); | |
821 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/create.json" : "/1/lists/members/create.json"), | |
822 | + param, | |
823 | + ref content, | |
824 | + null, | |
825 | + null); | |
792 | 826 | } |
793 | 827 | |
794 | 828 | //public HttpStatusCode CreateListMembers(string user, string list_id, string memberName, ref string content) |
@@ -820,11 +854,11 @@ namespace OpenTween | ||
820 | 854 | param.Add("screen_name", memberName); |
821 | 855 | param.Add("list_id", list_id); |
822 | 856 | return httpCon.GetContent(PostMethod, |
823 | - CreateTwitterUri("/1/lists/members/destroy.json"), | |
824 | - param, | |
825 | - ref content, | |
826 | - null, | |
827 | - null); | |
857 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/destroy.json" : "/1/lists/members/destroy.json"), | |
858 | + param, | |
859 | + ref content, | |
860 | + null, | |
861 | + null); | |
828 | 862 | } |
829 | 863 | |
830 | 864 | //public HttpStatusCode DeleteListMembers(string user, string list_id, string memberName, ref string content) |
@@ -858,17 +892,11 @@ namespace OpenTween | ||
858 | 892 | param.Add("screen_name", memberName); |
859 | 893 | param.Add("list_id", list_id); |
860 | 894 | return httpCon.GetContent(GetMethod, |
861 | - CreateTwitterUri("/1/lists/members/show.json"), | |
862 | - param, | |
863 | - ref content, | |
864 | - this.apiStatusHeaders, | |
865 | - GetApiCallback); | |
866 | - //return httpCon.GetContent(GetMethod, | |
867 | - // CreateTwitterUri("/1/" + user + "/" + list_id + "/members/" + id + ".json"), | |
868 | - // null, | |
869 | - // ref content, | |
870 | - // MyCommon.TwitterApiInfo.HttpHeaders, | |
871 | - // GetApiCallback); | |
895 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/lists/members/show.json" : "/1/lists/members/show.json"), | |
896 | + param, | |
897 | + ref content, | |
898 | + this.apiStatusHeaders, | |
899 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/lists/members/show") : GetApiCallback); | |
872 | 900 | } |
873 | 901 | #endregion |
874 | 902 |
@@ -880,12 +908,14 @@ namespace OpenTween | ||
880 | 908 | if (page > 0) |
881 | 909 | param.Add("page", page.ToString()); |
882 | 910 | |
911 | + // TODO: API v1.1 に存在しない API (旧 API で代替) | |
912 | + | |
883 | 913 | return httpCon.GetContent(GetMethod, |
884 | - CreateTwitterUri("/1/statuses/" + statusid.ToString()+ "/retweeted_by/ids.json"), | |
885 | - param, | |
886 | - ref content, | |
887 | - this.apiStatusHeaders, | |
888 | - GetApiCallback); | |
914 | + CreateTwitterUri("/1/statuses/" + statusid + "/retweeted_by/ids.json"), | |
915 | + param, | |
916 | + ref content, | |
917 | + this.apiStatusHeaders, | |
918 | + GetApiCallback); | |
889 | 919 | } |
890 | 920 | |
891 | 921 | public HttpStatusCode UpdateProfile(string name, string url, string location, string description, ref string content) |
@@ -899,11 +929,11 @@ namespace OpenTween | ||
899 | 929 | param.Add("include_entities", "true"); |
900 | 930 | |
901 | 931 | return httpCon.GetContent(PostMethod, |
902 | - CreateTwitterUri("/1/account/update_profile.json"), | |
903 | - param, | |
904 | - ref content, | |
905 | - null, | |
906 | - null); | |
932 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/update_profile.json" : "/1/account/update_profile.json"), | |
933 | + param, | |
934 | + ref content, | |
935 | + null, | |
936 | + null); | |
907 | 937 | } |
908 | 938 | |
909 | 939 | public HttpStatusCode UpdateProfileImage(FileInfo imageFile, ref string content) |
@@ -912,12 +942,12 @@ namespace OpenTween | ||
912 | 942 | binary.Add(new KeyValuePair<string, FileInfo>("image", imageFile)); |
913 | 943 | |
914 | 944 | return httpCon.GetContent(PostMethod, |
915 | - CreateTwitterUri("/1/account/update_profile_image.json"), | |
916 | - null, | |
917 | - binary, | |
918 | - ref content, | |
919 | - null, | |
920 | - null); | |
945 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/update_profile_image.json" : "/1/account/update_profile_image.json"), | |
946 | + null, | |
947 | + binary, | |
948 | + ref content, | |
949 | + null, | |
950 | + null); | |
921 | 951 | } |
922 | 952 | |
923 | 953 | public HttpStatusCode GetRelatedResults(long id, ref string content) |
@@ -927,42 +957,44 @@ namespace OpenTween | ||
927 | 957 | |
928 | 958 | param.Add("include_entities", "true"); |
929 | 959 | |
960 | + // TODO: API v1.1 に存在しない API (旧 API で代替) | |
961 | + | |
930 | 962 | return httpCon.GetContent(GetMethod, |
931 | - CreateTwitterUri("/1/related_results/show/" + id.ToString()+ ".json"), | |
932 | - param, | |
933 | - ref content, | |
934 | - this.apiStatusHeaders, | |
935 | - GetApiCallback); | |
963 | + CreateTwitterUri("/1/related_results/show/" + id + ".json"), | |
964 | + param, | |
965 | + ref content, | |
966 | + this.apiStatusHeaders, | |
967 | + GetApiCallback); | |
936 | 968 | } |
937 | 969 | |
938 | 970 | public HttpStatusCode GetBlockUserIds(ref string content) |
939 | 971 | { |
940 | 972 | return httpCon.GetContent(GetMethod, |
941 | - CreateTwitterUri("/1/blocks/blocking/ids.json"), | |
942 | - null, | |
943 | - ref content, | |
944 | - this.apiStatusHeaders, | |
945 | - GetApiCallback); | |
973 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/blocks/ids.json" : "/1/blocks/blocking/ids.json"), | |
974 | + null, | |
975 | + ref content, | |
976 | + this.apiStatusHeaders, | |
977 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/blocks/ids") : GetApiCallback); | |
946 | 978 | } |
947 | 979 | |
948 | 980 | public HttpStatusCode GetConfiguration(ref string content) |
949 | 981 | { |
950 | 982 | return httpCon.GetContent(GetMethod, |
951 | - CreateTwitterUri("/1/help/configuration.json"), | |
952 | - null, | |
953 | - ref content, | |
954 | - this.apiStatusHeaders, | |
955 | - GetApiCallback); | |
983 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/help/configuration.json" : "/1/help/configuration.json"), | |
984 | + null, | |
985 | + ref content, | |
986 | + this.apiStatusHeaders, | |
987 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/help/configuration") : GetApiCallback); | |
956 | 988 | } |
957 | 989 | |
958 | 990 | public HttpStatusCode VerifyCredentials(ref string content) |
959 | 991 | { |
960 | 992 | return httpCon.GetContent(GetMethod, |
961 | - CreateTwitterUri("/1/account/verify_credentials.json"), | |
962 | - null, | |
963 | - ref content, | |
964 | - this.apiStatusHeaders, | |
965 | - GetApiCallback); | |
993 | + CreateTwitterUri(HttpTwitter.API11Enabled ? "/1.1/account/verify_credentials.json" : "/1/account/verify_credentials.json"), | |
994 | + null, | |
995 | + ref content, | |
996 | + this.apiStatusHeaders, | |
997 | + HttpTwitter.API11Enabled ? CreateApi11Calllback("/account/verify_credentials") : GetApiCallback); | |
966 | 998 | } |
967 | 999 | |
968 | 1000 | #region Proxy API |
@@ -1015,6 +1047,15 @@ namespace OpenTween | ||
1015 | 1047 | MyCommon.TwitterApiInfo.UpdateFromHeader(this.apiStatusHeaders); |
1016 | 1048 | } |
1017 | 1049 | |
1050 | + private CallbackDelegate CreateApi11Calllback(string endpointName) | |
1051 | + { | |
1052 | + return (object sender, ref HttpStatusCode code, ref string content) => | |
1053 | + { | |
1054 | + if (code < HttpStatusCode.InternalServerError) | |
1055 | + MyCommon.TwitterApiInfo11.UpdateFromHeader(this.apiStatusHeaders, endpointName); | |
1056 | + }; | |
1057 | + } | |
1058 | + | |
1018 | 1059 | public HttpStatusCode UserStream(ref Stream content, |
1019 | 1060 | bool allAtReplies, |
1020 | 1061 | string trackwords, |
@@ -1029,10 +1070,10 @@ namespace OpenTween | ||
1029 | 1070 | param.Add("track", trackwords); |
1030 | 1071 | |
1031 | 1072 | return httpCon.GetContent(GetMethod, |
1032 | - CreateTwitterUserStreamUri("/2/user.json"), | |
1033 | - param, | |
1034 | - ref content, | |
1035 | - userAgent); | |
1073 | + CreateTwitterUserStreamUri(HttpTwitter.API11Enabled ? "/1.1/user.json" : "/2/user.json"), | |
1074 | + param, | |
1075 | + ref content, | |
1076 | + userAgent); | |
1036 | 1077 | } |
1037 | 1078 | |
1038 | 1079 | public HttpStatusCode FilterStream(ref Stream content, |
@@ -1046,10 +1087,10 @@ namespace OpenTween | ||
1046 | 1087 | param.Add("track", string.Join(",", trackwords.Split(" ".ToCharArray()))); |
1047 | 1088 | |
1048 | 1089 | return httpCon.GetContent(PostMethod, |
1049 | - CreateTwitterStreamUri("/1/statuses/filter.json"), | |
1050 | - param, | |
1051 | - ref content, | |
1052 | - userAgent); | |
1090 | + CreateTwitterStreamUri(HttpTwitter.API11Enabled ? "/1.1/statuses/filter.json" : "/1/statuses/filter.json"), | |
1091 | + param, | |
1092 | + ref content, | |
1093 | + userAgent); | |
1053 | 1094 | } |
1054 | 1095 | |
1055 | 1096 | public void RequestAbort() |
@@ -441,6 +441,27 @@ namespace OpenTween | ||
441 | 441 | } |
442 | 442 | |
443 | 443 | [DataContract] |
444 | + public class SearchResult11 // API v1.1 | |
445 | + { | |
446 | + [DataMember(Name = "statuses")] public List<Status> Statuses; | |
447 | + [DataMember(Name = "search_metadata")] public SearchMetadata11 SearchMetadata; | |
448 | + } | |
449 | + | |
450 | + [DataContract] | |
451 | + public class SearchMetadata11 // API v1.1 | |
452 | + { | |
453 | + [DataMember(Name = "max_id")] public long MaxId; | |
454 | + [DataMember(Name = "since_id")] public long SinceId; | |
455 | + [DataMember(Name = "refresh_url")] public string RefreshUrl; | |
456 | + [DataMember(Name = "next_results")] public string NextResults; | |
457 | + [DataMember(Name = "count")] public int Count; | |
458 | + [DataMember(Name = "completed_in")] public double CompletedIn; | |
459 | + [DataMember(Name = "since_id_str")] public string SinceIdStr; | |
460 | + [DataMember(Name = "query")] public string Query; | |
461 | + [DataMember(Name = "max_id_str")] public string MaxIdStr; | |
462 | + } | |
463 | + | |
464 | + [DataContract] | |
444 | 465 | public class SearchResult |
445 | 466 | { |
446 | 467 | [DataMember(Name = "completed_in")] public double CompletedIn; |
@@ -680,6 +680,7 @@ namespace OpenTween | ||
680 | 680 | } |
681 | 681 | |
682 | 682 | public static TwitterApiStatus TwitterApiInfo = new TwitterApiStatus(); |
683 | + public static TwitterApiStatus11 TwitterApiInfo11 = new TwitterApiStatus11(); | |
683 | 684 | |
684 | 685 | public static bool IsAnimatedGif(string filename) |
685 | 686 | { |
@@ -56,6 +56,7 @@ | ||
56 | 56 | <Compile Include="Api\ApiLimit.cs" /> |
57 | 57 | <Compile Include="Api\TwitterApiAccessLevel.cs" /> |
58 | 58 | <Compile Include="Api\TwitterApiStatus.cs" /> |
59 | + <Compile Include="Api\TwitterApiStatus11.cs" /> | |
59 | 60 | <Compile Include="ApplicationEvents.cs"> |
60 | 61 | <SubType>Code</SubType> |
61 | 62 | </Compile> |
@@ -1,6 +1,10 @@ | ||
1 | 1 | 更新履歴 |
2 | 2 | |
3 | 3 | ==== Ver 1.1.0-beta1(2013/xx/xx) |
4 | + * 当バージョンから Twitter API v1.1 に対応しています | |
5 | + * API v1.1 の使用に不都合がある場合は、ステータスバーのレートリミット表示をクリックすることで API v1 と切り替えることができます。 | |
6 | + | |
7 | + * NEW: API v1.1 に対応 | |
4 | 8 | * NEW: タブの表示位置を画面上部に変更可能に (thx @aokomoriuta!) |
5 | 9 | * NEW: mobile.twitter.com/<スクリーン名>/status/<ステータスID> のURLも関連発言表示の対象に追加 |
6 | 10 | * NEW: Favstarなどサードパーティ製サービスのパーマリンクURLも関連発言表示の対象に追加 |
@@ -40,12 +40,27 @@ namespace OpenTween | ||
40 | 40 | public ToolStripAPIGauge() |
41 | 41 | : base() |
42 | 42 | { |
43 | - this.Text = "API ???/???"; | |
43 | + this.Text = "API v1.1 ???/???"; | |
44 | 44 | this.ToolTipText = "API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)"; |
45 | 45 | |
46 | 46 | this.DisplayStyle = ToolStripItemDisplayStyle.Text; |
47 | 47 | } |
48 | 48 | |
49 | + [DefaultValue(true)] | |
50 | + [RefreshProperties(RefreshProperties.Repaint)] | |
51 | + public bool API11Enabled | |
52 | + { | |
53 | + get { return this._API11Enabled; } | |
54 | + set | |
55 | + { | |
56 | + this._API11Enabled = value; | |
57 | + | |
58 | + this.UpdateText(); | |
59 | + this.Invalidate(); | |
60 | + } | |
61 | + } | |
62 | + private bool _API11Enabled = true; | |
63 | + | |
49 | 64 | /// <summary> |
50 | 65 | /// ゲージに表示される横棒グラフの幅 |
51 | 66 | /// </summary> |
@@ -167,10 +182,16 @@ namespace OpenTween | ||
167 | 182 | |
168 | 183 | protected virtual void UpdateText() |
169 | 184 | { |
185 | + string apiVersionText; | |
170 | 186 | string remainCountText; |
171 | 187 | string maxCountText; |
172 | 188 | string minuteText; |
173 | 189 | |
190 | + if (this._API11Enabled) | |
191 | + apiVersionText = "v1.1"; | |
192 | + else | |
193 | + apiVersionText = "v1"; | |
194 | + | |
174 | 195 | if (this._ApiLimit == null) |
175 | 196 | { |
176 | 197 | remainCountText = "???"; |
@@ -184,8 +205,8 @@ namespace OpenTween | ||
184 | 205 | minuteText = Math.Ceiling(this.remainMinutes).ToString(); |
185 | 206 | } |
186 | 207 | |
187 | - var textFormat = "API {0}/{1}"; | |
188 | - this.Text = string.Format(textFormat, remainCountText, maxCountText); | |
208 | + var textFormat = "API {0} {1}/{2}"; | |
209 | + this.Text = string.Format(textFormat, apiVersionText, remainCountText, maxCountText); | |
189 | 210 | |
190 | 211 | var toolTipTextFormat = |
191 | 212 | "API rest {0}/{1}" + Environment.NewLine + |
@@ -555,7 +555,8 @@ namespace OpenTween | ||
555 | 555 | |
556 | 556 | SecurityManager = new InternetSecurityManager(PostBrowser); |
557 | 557 | |
558 | - MyCommon.TwitterApiInfo.AccessLimitUpdated += SetStatusLabelApiHandler; | |
558 | + MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated; | |
559 | + MyCommon.TwitterApiInfo11.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated; | |
559 | 560 | Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; |
560 | 561 | |
561 | 562 | string[] cmdArgs = Environment.GetCommandLineArgs(); |
@@ -9477,19 +9478,24 @@ namespace OpenTween | ||
9477 | 9478 | return slbl.ToString(); |
9478 | 9479 | } |
9479 | 9480 | |
9480 | - delegate void SetStatusLabelApiDelegate(); | |
9481 | - | |
9482 | - private void SetStatusLabelApiHandler(object sender, EventArgs e) | |
9481 | + private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e) | |
9483 | 9482 | { |
9484 | 9483 | try |
9485 | 9484 | { |
9486 | - if (InvokeRequired && !IsDisposed) | |
9485 | + if (this.InvokeRequired && !this.IsDisposed) | |
9487 | 9486 | { |
9488 | - Invoke(new SetStatusLabelApiDelegate(SetStatusLabelApi)); | |
9487 | + this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e))); | |
9489 | 9488 | } |
9490 | 9489 | else |
9491 | 9490 | { |
9492 | - SetStatusLabelApi(); | |
9491 | + if (sender is TwitterApiStatus11 && this._apiGauge.API11Enabled) | |
9492 | + { | |
9493 | + this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo11.AccessLimit["/statuses/home_timeline"]; | |
9494 | + } | |
9495 | + else if (sender is TwitterApiStatus && !this._apiGauge.API11Enabled) | |
9496 | + { | |
9497 | + this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit; | |
9498 | + } | |
9493 | 9499 | } |
9494 | 9500 | } |
9495 | 9501 | catch (ObjectDisposedException) |
@@ -9502,11 +9508,6 @@ namespace OpenTween | ||
9502 | 9508 | } |
9503 | 9509 | } |
9504 | 9510 | |
9505 | - private void SetStatusLabelApi() | |
9506 | - { | |
9507 | - this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit; | |
9508 | - } | |
9509 | - | |
9510 | 9511 | private void SetStatusLabelUrl() |
9511 | 9512 | { |
9512 | 9513 | StatusLabelUrl.Text = GetStatusLabelText(); |
@@ -12184,7 +12185,18 @@ namespace OpenTween | ||
12184 | 12185 | this.gh.NotifyClicked += GrowlHelper_Callback; |
12185 | 12186 | |
12186 | 12187 | this._apiGauge = new ToolStripAPIGauge(); |
12187 | - this._apiGauge.DoubleClick += this.ApiUsageInfoMenuItem_Click; | |
12188 | + this._apiGauge.Click += (s, e) => | |
12189 | + { | |
12190 | + var api11Enabled = !HttpTwitter.API11Enabled; | |
12191 | + | |
12192 | + HttpTwitter.API11Enabled = api11Enabled; | |
12193 | + (s as ToolStripAPIGauge).API11Enabled = api11Enabled; | |
12194 | + | |
12195 | + if (api11Enabled) | |
12196 | + MyCommon.TwitterApiInfo11.Reset(); | |
12197 | + else | |
12198 | + MyCommon.TwitterApiInfo.Reset(); | |
12199 | + }; | |
12188 | 12200 | this.StatusStrip1.Items.Insert(2, this._apiGauge); |
12189 | 12201 | |
12190 | 12202 | this.ReplaceAppName(); |
@@ -170,12 +170,31 @@ namespace OpenTween | ||
170 | 170 | |
171 | 171 | //private List<PostClass> _deletemessages = new List<PostClass>(); |
172 | 172 | |
173 | + public TwitterApiAccessLevel AccessLevel | |
174 | + { | |
175 | + get | |
176 | + { | |
177 | + if (HttpTwitter.API11Enabled) | |
178 | + return MyCommon.TwitterApiInfo11.AccessLevel; | |
179 | + else | |
180 | + return MyCommon.TwitterApiInfo.AccessLevel; | |
181 | + } | |
182 | + } | |
183 | + | |
184 | + protected void ResetApiStatus() | |
185 | + { | |
186 | + if (HttpTwitter.API11Enabled) | |
187 | + MyCommon.TwitterApiInfo11.Reset(); | |
188 | + else | |
189 | + MyCommon.TwitterApiInfo.Reset(); | |
190 | + } | |
191 | + | |
173 | 192 | public string Authenticate(string username, string password) |
174 | 193 | { |
175 | 194 | HttpStatusCode res; |
176 | 195 | var content = ""; |
177 | 196 | |
178 | - MyCommon.TwitterApiInfo.Reset(); | |
197 | + this.ResetApiStatus(); | |
179 | 198 | try |
180 | 199 | { |
181 | 200 | res = twCon.AuthUserAndPass(username, password, ref content); |
@@ -227,7 +246,7 @@ namespace OpenTween | ||
227 | 246 | //OAuth PIN Flow |
228 | 247 | bool res; |
229 | 248 | |
230 | - MyCommon.TwitterApiInfo.Reset(); | |
249 | + this.ResetApiStatus(); | |
231 | 250 | try |
232 | 251 | { |
233 | 252 | res = twCon.AuthGetRequestToken(ref pinPageUrl); |
@@ -245,7 +264,7 @@ namespace OpenTween | ||
245 | 264 | HttpStatusCode res; |
246 | 265 | var content = ""; |
247 | 266 | |
248 | - MyCommon.TwitterApiInfo.Reset(); | |
267 | + this.ResetApiStatus(); | |
249 | 268 | try |
250 | 269 | { |
251 | 270 | res = twCon.AuthGetAccessToken(pinCode); |
@@ -295,7 +314,7 @@ namespace OpenTween | ||
295 | 314 | public void ClearAuthInfo() |
296 | 315 | { |
297 | 316 | Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; |
298 | - MyCommon.TwitterApiInfo.Reset(); | |
317 | + this.ResetApiStatus(); | |
299 | 318 | twCon.ClearAuthInfo(); |
300 | 319 | } |
301 | 320 |
@@ -366,7 +385,7 @@ namespace OpenTween | ||
366 | 385 | { |
367 | 386 | Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; |
368 | 387 | } |
369 | - MyCommon.TwitterApiInfo.Reset(); | |
388 | + this.ResetApiStatus(); | |
370 | 389 | twCon.Initialize(token, tokenSecret, username, userId); |
371 | 390 | _uname = username.ToLower(); |
372 | 391 | if (AppendSettingDialog.Instance.UserstreamStartup) this.ReconnectUserStream(); |
@@ -752,7 +771,8 @@ namespace OpenTween | ||
752 | 771 | if (MyCommon._endingFlag) return ""; |
753 | 772 | |
754 | 773 | if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return ""; |
755 | - if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.Read || MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
774 | + | |
775 | + if (this.AccessLevel == TwitterApiAccessLevel.Read || this.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
756 | 776 | { |
757 | 777 | return "Auth Err:try to re-authorization."; |
758 | 778 | } |
@@ -970,7 +990,8 @@ namespace OpenTween | ||
970 | 990 | if (MyCommon._endingFlag) return ""; |
971 | 991 | |
972 | 992 | if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return ""; |
973 | - if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.Read || MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
993 | + | |
994 | + if (this.AccessLevel == TwitterApiAccessLevel.Read || this.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
974 | 995 | { |
975 | 996 | return "Auth Err:try to re-authorization."; |
976 | 997 | } |
@@ -2248,6 +2269,56 @@ namespace OpenTween | ||
2248 | 2269 | return ""; |
2249 | 2270 | } |
2250 | 2271 | |
2272 | + // API v1.1 | |
2273 | + private string CreatePostsFromSearch11Json(string content, TabClass tab, bool read, int count, ref long minimumId, bool more) | |
2274 | + { | |
2275 | + TwitterDataModel.SearchResult11 items; | |
2276 | + try | |
2277 | + { | |
2278 | + items = MyCommon.CreateDataFromJson<TwitterDataModel.SearchResult11>(content); | |
2279 | + } | |
2280 | + catch (SerializationException ex) | |
2281 | + { | |
2282 | + MyCommon.TraceOut(ex.Message + Environment.NewLine + content); | |
2283 | + return "Json Parse Error(DataContractJsonSerializer)"; | |
2284 | + } | |
2285 | + catch (Exception ex) | |
2286 | + { | |
2287 | + MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content); | |
2288 | + return "Invalid Json!"; | |
2289 | + } | |
2290 | + foreach (var result in items.Statuses) | |
2291 | + { | |
2292 | + PostClass post = null; | |
2293 | + post = CreatePostsFromStatusData(result); | |
2294 | + if (post == null) continue; | |
2295 | + | |
2296 | + if (minimumId > post.StatusId) minimumId = post.StatusId; | |
2297 | + if (!more && post.StatusId > tab.SinceId) tab.SinceId = post.StatusId; | |
2298 | + //二重取得回避 | |
2299 | + lock (LockObj) | |
2300 | + { | |
2301 | + if (tab == null) | |
2302 | + { | |
2303 | + if (TabInformations.GetInstance().ContainsKey(post.StatusId)) continue; | |
2304 | + } | |
2305 | + else | |
2306 | + { | |
2307 | + if (TabInformations.GetInstance().ContainsKey(post.StatusId, tab.TabName)) continue; | |
2308 | + } | |
2309 | + } | |
2310 | + | |
2311 | + post.IsRead = read; | |
2312 | + if ((post.IsMe && !read) && this._readOwnPost) post.IsRead = true; | |
2313 | + | |
2314 | + if (tab != null) post.RelTabName = tab.TabName; | |
2315 | + //非同期アイコン取得&StatusDictionaryに追加 | |
2316 | + TabInformations.GetInstance().AddPost(post); | |
2317 | + } | |
2318 | + | |
2319 | + return ""; | |
2320 | + } | |
2321 | + | |
2251 | 2322 | private string CreatePostsFromSearchJson(string content, TabClass tab, bool read, int count, ref long minimumId, bool more) |
2252 | 2323 | { |
2253 | 2324 | TwitterDataModel.SearchResult items; |
@@ -2715,7 +2786,10 @@ namespace OpenTween | ||
2715 | 2786 | |
2716 | 2787 | if (!TabInformations.GetInstance().ContainsTab(tab)) return ""; |
2717 | 2788 | |
2718 | - return this.CreatePostsFromSearchJson(content, tab, read, count, ref tab.OldestId, more); | |
2789 | + if (HttpTwitter.API11Enabled) | |
2790 | + return this.CreatePostsFromSearch11Json(content, tab, read, count, ref tab.OldestId, more); | |
2791 | + else | |
2792 | + return this.CreatePostsFromSearchJson(content, tab, read, count, ref tab.OldestId, more); | |
2719 | 2793 | } |
2720 | 2794 | |
2721 | 2795 | public string GetPhoenixSearch(bool read, |
@@ -2918,7 +2992,8 @@ namespace OpenTween | ||
2918 | 2992 | if (MyCommon._endingFlag) return ""; |
2919 | 2993 | |
2920 | 2994 | if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return ""; |
2921 | - if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.Read || MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
2995 | + | |
2996 | + if (this.AccessLevel == TwitterApiAccessLevel.Read || this.AccessLevel == TwitterApiAccessLevel.ReadWrite) | |
2922 | 2997 | { |
2923 | 2998 | return "Auth Err:try to re-authorization."; |
2924 | 2999 | } |
@@ -4088,7 +4163,7 @@ namespace OpenTween | ||
4088 | 4163 | } |
4089 | 4164 | catch(Exception) |
4090 | 4165 | { |
4091 | - MyCommon.TwitterApiInfo.Reset(); | |
4166 | + this.ResetApiStatus(); | |
4092 | 4167 | return false; |
4093 | 4168 | } |
4094 | 4169 |