How to get twitter daily trends programmatically using REST API

by Viper 22. May 2009 04:44

This code snippet shows you how you can get twitter daily trends using TweetSharp API. It is very important that you get latest code for the API. There was a bug in Trend API that I discovered and got fixed from the developers of the API.


static void GetDailyTrends()
{
 IFluentTwitter ft = FluentTwitter.CreateRequest();
 ft.AuthenticateAs(LOGIN_NAME, PASSWORD);
 ft.Search().Trends().Daily().AsJson();
 var resp = ft.Request();
 if (null != resp)
 {
  var trends = resp.AsTrends();
  if (null != trends)
  {
   foreach (TwitterSearchTrend trend in trends.Trends)
   {
    Console.WriteLine("Query: {0}\tName: {1}", 
       trend.Query.PadRight(40), trend.Name);
   }
  }
 }
}

Outpt of this console application looks like below.

Query: "American Idol" OR #idol       Name: American Idol
Query: Cavs                           Name: Cavs
Query: "Kris Allen"                   Name: Kris Allen
Query: "Adam Lambert" OR Lambert      Name: Adam Lambert
Query: LeBron                         Name: LeBron
Query: Cleveland                      Name: Cleveland
Query: Kobe                           Name: Kobe
Query: Kiss                           Name: Kiss
Query: NBA                            Name: NBA
Query: #americanidol                  Name: #americanidol
Query: "Rashard Lewis"                Name: Rashard Lewis
Query: "Top Echelon Network"          Name: Top Echelon Network
Query: "Go Magic" OR Magic            Name: Go Magic
Query: Glee                           Name: Glee
Query: "Star Trek"                    Name: Star Trek
Query: Lakers                         Name: Lakers
Query: Adam's                         Name: Adam's
Query: "Terminator Salvation"         Name: Terminator Salvation
Query: Goodnight                      Name: Goodnight
Query: Queen                          Name: Queen
Give your advice to big bosses and make money

Views: 2774

Tags: ,

Twitter | Twitter

Comments

6/5/2009 2:09:02 PM #

lessofthat

thanks - I hadn't realised you needed to specify Daily / Weekly and it was causing me pain!

lessofthat United Kingdom

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

By Categories