How get weekly twitter trends using REST API

by Viper 22. May 2009 14:50

This code sample will show how you can get weekly trends using REST API. The sample shows another feature of the API where you can specify a criteria to limit the results. You can specify a start date for the report. This is set by calling On method on ITwitterSearchTrends.


static List GetWeeklyTrends(DateTime ? onDate)
{
 TwitterClientInfo clientInfo = new TwitterClientInfo();
 clientInfo.ClientName = "Marketweet";
 clientInfo.ClientUrl = "http://www.byteblocks.com";
 clientInfo.ClientVersion = "1.1";
 List trendNames = new List();
 IFluentTwitter ft = FluentTwitter.CreateRequest(clientInfo);
 ft.AuthenticateAs(LOGIN_NAME, PASSWORD);
 ITwitterSearchTrends searchTrends = ft.Search().Trends().Weekly();
 if (null != onDate)
 {
  searchTrends.On(onDate.Value).AsJson();
 }
 var resp = ft.Request();
 if (null != resp)
 {
  var trends = resp.AsTrends();
  if (null != trends)
  {
   foreach (TwitterSearchTrend trend in trends.Trends)
   {
    trendNames.Add(trend.Name);
   }
  }
 }
 return trendNames;
}

Views: 1007

Tags: ,

Twitter

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli