}
[Fact]
+ public async Task StatusesUserTimeline_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterStatus[]>(
+ new Uri("statuses/user_timeline.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "screen_name", "twitterapi" },
+ { "include_rts", "true" },
+ { "include_entities", "true" },
+ { "include_ext_alt_text", "true" },
+ { "count", "200" },
+ { "max_id", "900" },
+ { "since_id", "100" },
+ },
+ "/statuses/user_timeline")
+ )
+ .ReturnsAsync(new TwitterStatus[0]);
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.StatusesUserTimeline("twitterapi", count: 200, maxId: 900L, sinceId: 100L)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task StatusesShow_Test()
{
using (var twitterApi = new TwitterApi())
return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/statuses/mentions_timeline");
}
+ public Task<TwitterStatus[]> StatusesUserTimeline(string screenName, int? count = null, long? maxId = null, long? sinceId = null)
+ {
+ var endpoint = new Uri("statuses/user_timeline.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["screen_name"] = screenName,
+ ["include_rts"] = "true",
+ ["include_entities"] = "true",
+ ["include_ext_alt_text"] = "true",
+ };
+
+ if (count != null)
+ param["count"] = count.ToString();
+ if (maxId != null)
+ param["max_id"] = maxId.ToString();
+ if (sinceId != null)
+ param["since_id"] = sinceId.ToString();
+
+ return this.apiConnection.GetAsync<TwitterStatus[]>(endpoint, param, "/statuses/user_timeline");
+ }
+
public Task<TwitterStatus> StatusesShow(long statusId)
{
var endpoint = new Uri("statuses/show.json", UriKind.Relative);
this.Initialize("", "", "", 0);
}
- public HttpStatusCode UserTimeline(long? user_id, string screen_name, int? count, long? max_id, long? since_id, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
-
- if ((user_id == null && string.IsNullOrEmpty(screen_name)) ||
- (user_id != null && !string.IsNullOrEmpty(screen_name))) return HttpStatusCode.BadRequest;
-
- if (user_id != null)
- param.Add("user_id", user_id.ToString());
- if (!string.IsNullOrEmpty(screen_name))
- param.Add("screen_name", screen_name);
- if (count != null)
- param.Add("count", count.ToString());
- if (max_id != null)
- param.Add("max_id", max_id.ToString());
- if (since_id != null)
- param.Add("since_id", since_id.ToString());
-
- param.Add("include_rts", "true");
- param.Add("include_entities", "true");
- param.Add("include_ext_alt_text", "true");
-
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/statuses/user_timeline.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/statuses/user_timeline"));
- }
-
public HttpStatusCode DirectMessages(int? count, long? max_id, long? since_id, ref string content)
{
Dictionary<string, string> param = new Dictionary<string, string>();
catch (WebApiException ex)
{
this._myStatusError = true;
- this.StatusLabel.Text = ex.Message;
+ this.StatusLabel.Text = $"Err:{ex.Message}(GetUserTimeline)";
}
finally
{
p.Report("UserTimeline refreshing...");
- await Task.Run(() =>
+ await Task.Run(async () =>
{
WebApiException lastException = null;
if (string.IsNullOrEmpty(tab.User))
continue;
- this.tw.GetUserTimelineApi(read, tab.User, tab, loadMore);
+ await this.tw.GetUserTimelineApi(read, tab.User, tab, loadMore)
+ .ConfigureAwait(false);
}
catch (WebApiException ex)
{
}
}
- public void GetUserTimelineApi(bool read,
- string userName,
- TabClass tab,
- bool more)
+ public async Task GetUserTimelineApi(bool read, string userName, TabClass tab, bool more)
{
this.CheckAccountState();
- HttpStatusCode res;
- var content = "";
var count = GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, more, false);
- try
+ TwitterStatus[] statuses;
+ if (string.IsNullOrEmpty(userName))
+ {
+ var target = tab.User;
+ if (string.IsNullOrEmpty(target)) return;
+ userName = target;
+ statuses = await this.Api.StatusesUserTimeline(userName, count)
+ .ConfigureAwait(false);
+ }
+ else
{
- if (string.IsNullOrEmpty(userName))
+ if (more)
{
- var target = tab.User;
- if (string.IsNullOrEmpty(target)) return;
- userName = target;
- res = twCon.UserTimeline(null, target, count, null, null, ref content);
+ statuses = await this.Api.StatusesUserTimeline(userName, count, maxId: tab.OldestId)
+ .ConfigureAwait(false);
}
else
{
- if (more)
- {
- res = twCon.UserTimeline(null, userName, count, tab.OldestId, null, ref content);
- }
- else
- {
- res = twCon.UserTimeline(null, userName, count, null, null, ref content);
- }
+ statuses = await this.Api.StatusesUserTimeline(userName, count)
+ .ConfigureAwait(false);
}
}
- catch(Exception ex)
- {
- throw new WebApiException("Err:" + ex.Message, ex);
- }
-
- if (res == HttpStatusCode.Unauthorized)
- throw new WebApiException("Err:@" + userName + "'s Tweets are protected.");
-
- this.CheckStatusCode(res, content);
- var minimumId = CreatePostsFromJson(content, MyCommon.WORKERTYPE.UserTimeline, tab, read);
+ var minimumId = CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.UserTimeline, tab, read);
if (minimumId != null)
tab.OldestId = minimumId.Value;