public GetProfile ( string screenName, int count, bool includeRetweets, bool includeReplies ) : IList |
||
screenName | string | |
count | int | |
includeRetweets | bool | |
includeReplies | bool | |
리턴 | IList |
public IList<TwitterStatus> GetProfile(string screenName, int count, bool includeRetweets, bool includeReplies)
{
var result = Query("https://api.twitter.com/1.1/statuses/user_timeline.json",
new[] {
new KeyValuePair<String, String>("screen_name", screenName),
new KeyValuePair<String, String>("count", count.ToString()),
new KeyValuePair<String, String>("include_rts", includeRetweets.ToString()),
new KeyValuePair<String, String>("exclude_replies", (!includeReplies).ToString()),
});
var serializer = new JavaScriptSerializer();
var searchResult = serializer.Deserialize<List<Response>>(result);
return searchResult.Select(s => new TwitterStatus {
CreatedAt = ParseDateTime(s.created_at),
Text = s.text,
User = new TwitterUser {
Id = s.user.id,
Description = s.user.description,
Location = s.user.location,
Name = s.user.name,
ProfileImageUrl = s.user.profile_image_url,
ScreenName = s.user.screen_name
}
}).ToList();
}
/// <summary> /// Get the Profile tweets from the Twitter API. Cache the results. /// </summary> /// <returns></returns> private IList <TwitterStatus> GetProfile() { var cacheKey = String.Format("__TwitterProfile_{0}_{1}_{2}_{3}", this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies); var results = (IList <TwitterStatus>) this.Context.Cache[cacheKey]; if (results == null) { var api = new TwitterAPI(); try { results = api.GetProfile(this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies); } catch { return(null); } this.Context.Cache.Insert( cacheKey, results, null, DateTime.UtcNow.AddSeconds(this.CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration ); } return(results); }