Introduction

Microsoft WebMatrix provides an easy way to get started with web development, and together with new Razor syntax for ASP.NET Web Pages it includes everything you need to get your web site up, running and integrated with many other sites and networks, in a short period of time. The WebMatrix helpers are designed to make your life easier when creating web sites. They provide you a simple and consistent way of performing common web development tasks that otherwise would require a great deal of custom coding. With a few lines of code you should be able to secure your web site using membership, store information in Windows Azure Storage, integrate your site with Facebook, among others things.

The Twitter Helper for WebMatrix makes it simple to integrate several Twitter social features in your site. For example, you can display Twitter widgets like "Follow Me" and "Tweet" Buttons, and access the Timeline Resources exposed by the Twitter API in a few lines of code.

Depending on the helper feature you want to use, the helper requires that you call an initialization method. Check the Documentation page to check each case. For using helper methods without initialization see the Getting Started in 60 seconds (without initialization) section, otherwise see the Getting Started in 60 seconds (with initialization) section.

Getting Started in 60 Seconds (without Initialization)

Download the helper package and extract its content in the root folder of your WebMatrix site. To try the helper in any WebMatrix page, add the following line to display a "Search" Widget:

@Twitter.Search("webmatrix")

Getting Started in 60 Seconds (with Initialization)

These steps will guide you on how to display the Twitter public timeline in your site: 

  1. Register a new Twitter application and make note of the consumer key and secret.
  2. Download the helper package and extract its content in the root folder of your WebMatrix site.
  3. Add the following line to the _AppStart.cshtml page of your WebMatrix Site (if the file does not already exist, create it in the root of the website). Replace the placeholders with your Twitter consumer key and secret.
    @{
        Twitter.Initialize("{consumer-key}", "{consumer-secret}");    
    }
  4. In any WebMatrix page, add the following code to display the Twitter public timeline:
    @{
        var timeline = Twitter.GetPublicTimeline();
        var grid = new WebGrid(timeline, columnNames : new []{"Text"});
    }
    ...
    @grid.GetHtml()

 

Documentation and Samples

Helper reference is available here. Optionally, you can download a sample WebMatrix web site where you can see the helper in action. To download and run it with Microsoft WebMatrix, follow these steps:

  1. Download the sample site from the Downloads section. Extract the contents and open the folder in WebMatrix.
  2. Register a new Twitter application and make note of the Consumer Key and Secret.
  3. Configure your Twitter consumer key and secret in the _AppStart.cshtml page of the sample site.
  4. Run the sample! It contains code samples and examples of the features provided by the helper.

Other Useful Resources

Don't miss the helper's getting started screencast.

You can find more information about the Twitter API in http://dev.twitter.com/doc.

Learn more on WebMatrix, ASP.NET Web Pages and the Razor Syntax with the WebMatrix tutorials.

Last edited Jan 7, 2011 at 2:00 PM by jsenior, version 12