5.7 KiB
uid | title | author | description | ms.author | manager | ms.date | ms.topic | ms.assetid | ms.technology | ms.prod | msc.legacyurl | msc.type |
---|---|---|---|---|---|---|---|---|---|---|---|---|
web-pages/overview/ui-layouts-and-themes/twitter-helper | Twitter Helper with ASP.NET Web Pages | Microsoft Docs | tfitzmac | This topic and application show how to add a Twitter Helper to your WebMatrix 3 project. It contains the Twitter Helper code and shows how to call the helper... | aspnetcontent | wpickett | 02/07/2014 | article | c1a1244e-b9c8-42e6-a00b-8456a4ec027c | dotnet-webpages | .net-framework | /web-pages/overview/ui-layouts-and-themes/twitter-helper | authoredcontent |
Twitter Helper with ASP.NET Web Pages
This topic and application show how to add a Twitter Helper to your WebMatrix 3 project. It contains the Twitter Helper code and shows how to call the helper methods.
This code for the Twitter.cshtml file was developed by Tian Pan of Microsoft.
Software versions used in the tutorial
- ASP.NET Web Pages (Razor) 3
This tutorial also works with ASP.NET Web Pages 2.
Introduction
This topic demonstrates how to add a Twitter Helper to your application and use Razor syntax to call the helper methods. The Twitter Helper makes it easy to incorporate Twitter buttons and widgets in your application. To use a Twitter widget, such as a user's timeline or the search results for a hashtag, you must first create the widget on Twitter. After creating your widget, you will receive a widget id. You pass this widget id as a parameter when calling the helper methods that show widget.
This topic was written for version 1.1 of the Twitter API. By directly adding the Twitter Helper code to your project, you can update the helper code if the Twitter API changes.
For information about installing WebMatrix, see Introducing ASP.NET Web Pages 2 - Getting Started.
Add Twitter Helper to your project
To add the Twitter Helper, first, add a folder named App_Code to your project. Then, create a file named Twitter.cshtml.
Replace the default code in Twitter.cshtml with the following code.
[!code-cshtmlMain]
Call Twitter methods from your web pages
The following example shows how to use the Twitter Helper methods from a page in your project. In your project, you will want to replace the parameter values with values that are relevant to your needs. You can use the provided widget ids to explore how the methods work, but you will want to generate your own widgets for your project.
Not all of the parameters shown below are required. The optional parameters are used to customize how the button or widget is displayed. For example, the Follow Button only requires the user name to follow, but the example shows how to include the number of followers, and how specify the size of the button and the language.
[!code-htmlMain]
See the results
The above code produces the following buttons and widgets. These buttons and widgets are fully-functional, not screenshots. The Follow Button is displayed in Spanish because the language parameter was set to es.
Follow Button
Tweet Button
User Timeline (Profile)
Favorites
List
Tweets from @Microsoft/MS_Consumer_Bands