Great Ideas. Always Flowing.

We are not happy until you are happy. Client satisfaction guaranteed. Whatever your needs and requirements, we have the skills and resources for the job!

Recently Viewed...

To help you navigate to pages you most recently visited, select from the links below.    
Installing DotNetNuke 6.0
Installing / Setup of SharePoint 2010 Part 2
Installing Microsoft SharePoint Foundation (MSF)...

DNN Development

DotNetNuke Gold Benefactor DotNetNuke Powered!

 

Data Springs offers custom DNN development and module enhancements. Besides our growing list of complementary products, we can help with almost any of your other DNN needs or integrations.

 

Get a free quote for your needs...

SnowCovered Top Sellers

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet or record live videos from your webcam.

Build high performance, completely customizable data-entry forms and views driven by your DNN and external databases. New built-in tools make it a snap to quickly create data entry forms, data views, and even database tables. Plus, add your own HTML, CSS, Javascript, SQL commands, stored procedures,

The most advanced DotNetNuke shopping cart on the planet. Easy to use e-Commerce, Secure Shopping Cart Software and SEO friendly. B2C / B2B Ecommerce Sites.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

Popular Tags...

Popular tags...

How to Setup Twitter Integration


Registered users can also download Linq2Twitter sample. Please register an account to get a copy.


In this article:

  • AuthenticationAccount Information
  • Friends and Followers
  • Get Statuses and Retweets
  • Update Status
  • How to Retweet
  • References

Introduction

Twitter is a micro-blogging service that allows people to post messages. The maximum length of each message is 140 characters. Twitter enables social networking by allowing people to follow and communicate with each other. Over time, this has proven to be a powerful communications medium because of its real-time nature.

Whenever news breaks around the world, people are tweeting that news as it happens. This article will talk about how to integrate twitter API into ASP.NET application. There are few libraries introduced in twitter developer website for using in .NET application

All may have its own pros & cons. This article will focused on LinqToTwitter library which as its name shown completely based on linQ. You can download the source code or dll’s from codeplex. Then you should add references to your web applications.



How to Start

First thing you should consider for creating any twitter application is you have to register the application and get Consumer key and Consumer secret:



These keys should be kept on safe place.  Web.config is good place to put these keys and it is easy to access them through all places in ASP.NET application.

Authentication


Twitter has recently changed its authentication from basic to OAuth authentication. OAuth is a security protocol that allows applications to act on your behalf without requiring you to give out your password to every application. This definition is a generalization and simplification of what OAuth truly is.

There is an increasing need for Web applications to communicate with each other. In the Twitter space, there are literally hundreds of 3rd party applications that access Twitter on your behalf to provide functionality. Examples include posting photos, scheduling tweets, and full-featured clients.

Many of these applications fill holes in Twitter's offerings and deliver value, contributing to their popularity. Without OAuth, each of these applications would need to collect your username and password to interact with Twitter on your behalf and therein lays the problem.

Sharing secrets (credentials) with a 3rd party application requires putting trust in that application to act responsibly. This is a risky proposition because eventually some unscrupulous application will misuse your secrets for their own gain or engage in malicious behavior. Therefore, you need to minimize who you share your secrets with.

Adding to the unfortunate circumstances of finding yourself in a position where an application has misused secrets, the first line of defense is to change passwords. The problem with changing passwords is that the same password has been given to multiple other applications.

Therefore, after changing your Twitter password, you also need to change passwords for every other application. Giving out secrets to every application is fraught with risk and complication.

OAuth is a way to enable the scenario of working with 3rd party applications, without giving out your secrets. Essentially, a 3rd party application that wants to access your Twitter account, using OAuth, will perform a redirection to an authorization page on Twitter, you will then tell Twitter to give them permission, and the application will be able to perform actions on your behalf.

This whole sequence of events occurs without needing to share a password with the 3rd party site. Instead, Twitter has shared a token to your account that the 3rd party application uses. If later, you find that you can't trust the 3rd party application, go to Twitter and cancel their access and Twitter will no longer allow that specific application to access your account.

Because access is controlled through Twitter, you don't have to do anything special for other applications because they still have access to your account. No one has your Twitter password and you don't have to encounter the pain of visiting every site.

OAuth is really the way forward in building applications that work with Twitter. By implementing OAuth, you can instill a degree of trust in your application because visitors know that you're taking a responsible approach, rather than asking them to unnecessarily share secrets.

I encourage you to use OAuth in all of your application development endeavors, which is fully supported by LINQ to Twitter. Anyway let’s do some coding; this code will do the authentication: 
private WebAuthorizer auth;

protected void Page_Load(object sender, EventArgs e)
{
IOAuthCredentials credentials = new SessionStateCredentials();

if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
}

auth = new WebAuthorizer
{
Credentials = credentials,
PerformRedirect = authUrl => Response.Redirect(authUrl)
};

if (!Page.IsPostBack)
{
auth.CompleteAuthorization(Request.Url);
}

if (string.IsNullOrWhiteSpace(credentials.ConsumerKey) ||
string.IsNullOrWhiteSpace(credentials.ConsumerSecret))
{
// The user needs to set up the web.config file to include Twitter consumer key and secret.
lblInfo.Text = "Please set up Consumekey and ConsumerSecret in your web.config";
}
else if (auth.IsAuthorized)
{
screenNameLabel.Text = "Logged in as " + auth.ScreenName;
lblInfo.Text = "";
}
else {

lblInfo.Text = "You are not authorized from twitter.";
}

}

protected void authorizeTwitterButton_Click(object sender, EventArgs e)
{
auth.BeginAuthorization(Request.Url);
}

The WebAuthorizer class is the class will do the OAuth authentication for you, when user click on authorize button the browser will be redirected to a page like this:



So the page will redirect to twitter site and user will pass his username/password to twitter website, not the application. After successful authentication the page will be redirect to application callback URL and IOAuthCredentials property of WebAuthorizer class is loaded now.

Now the user is authenticated and can use his/her twitter account through the application features. There are few points should be considered, the credential will hold OAuthToken and AccessToken from twitter, these values can be hold in a Session and set in SessionStateCredentials class so user doesn’t need to login again and again when navigating through different pages of application, they can also save in database and in this way user will login into the website just once.

Account Information


Account class hold information related to twitter account, this contains numbers of Friends ( following account ) , Followers, Updates and favorites. So to get these information a linQ query should be written from this class:

twitterCtx = new TwitterContext(auth);
var accountTotals =
(from acct in twitterCtx.Account
where acct.Type == AccountType.Totals
select acct.Totals)
.SingleOrDefault();

lblFriends.Text = accountTotals.Friends.ToString();
lblFollowers.Text = accountTotals.Followers.ToString();
lblupdates.Text = accountTotals.Updates.ToString();
lblFavourites.Text = accountTotals.Favorites.ToString();

From a coding experience perspective, the TwitterContext type is analogous to DataContext (LINQ to SQL) or ObjectContext (LINQ to Entities). TwitterContext instance, twitterCtx uses to access IQueryable<T> tweet categories.

Each tweet category has a Type property for the type of tweets wants to get back. For example, Status tweets can be made for Public, Friend, or User timelines. Each tweet category has a type enum to helps figure out what is available.

Just like other LINQ providers, IQueryable<T>returns from the query. You can see how to materialize the query by invoking the ToList operator. Just like other LINQ providers, LINQ to Twitter does deferred execution, so operators such as ToList and ToArray or statements such as for and foreach loops will cause the query to execute and make the actual call to Twitter.


Friends and Followers


Now to get details on these data, some other queries should be used from other classes. User class is used to get details about friends and followers:
twitterCtx = new TwitterContext(auth);

var friends =
from tweet in twitterCtx.User
where tweet.Type == UserType.Friends &&
tweet.ID == auth.UserId
select tweet;


gvFriends.DataSource = friends;
gvFriends.DataBind();

var followers =
from tweet in twitterCtx.User
where tweet.Type == UserType.Followers &&
tweet.ID == auth.UserId
select tweet;


gvFollowers.DataSource = followers;
gvFollowers.DataBind();

This class contains other information related to user like Categories, Lookup and Search. This can be used the same way as Friends and followers.

Get Statuses and Retweets


To get statuses from your friends Status class can be queries, it contains different type of filters which can be included in Where clause. As an example this block of code will return statuses by friends:

twitterCtx = new TwitterContext(auth);
var tweets =
from tweet in twitterCtx.Status
where tweet.Type == StatusType.Friends
select tweet;

StatusType is an enum which can be used to get retweets by me, or retweets by specific user and also retweets by/to me/user. Nice and easy.

Update Status

Updating status is very easy and one line of the code:

twitterCtx.UpdateStatus(“New status”);

There are many overloads for this method, for example it gets inReplyToStatusId , Latitude, Longitude, placeId

How to Retweet


Again this part is very easy, only StatusID of tweet is needed:

twitterCtx = new TwitterContext(auth);

var retweet = twitterCtx.Retweet(txtStatusId.Text);

lblInfo.Text = "User: " + retweet.Retweet.RetweetingUser.Name +
" - Tweet: " + retweet.Retweet.Text +
" - Tweet ID: " + retweet.Retweet.ID

Retweet method returns a Status object which holds information related to the tweet.

References

Registered users can also download Linq2Twitter sample. Please register an account to get a copy.

Feedback Comments

Feedback

DNN Modules

DotNetNuke Modules


Data Springs offers cost-saving packages that fit your needs:

Purchase the Collection 6.0

Data Springs Collection 6.0

An entire tool chest to quickly build websites and construct complex, powerful, and relevant workflow. Elevate your design with custom registration, forms, displays, reports, user management, payments, Google maps,, SQL updates, and so much more!

Best Value!  Includes all DotNetNuke modules by Data Springs.

$ 495.00

Data Springs User Management Suite 3.0

All the tools you need to enhance user & profile management from A to Z!.  A comprehensive package with 5 feature-packed modules that offer extensive admin controls and easy user interface geared towards an effective and growth-oriented site!  .... more

 

Includes:  Dynamic Registration     Dynamic Login   ♦   Interactive User Import     Dynamic User Directory   ♦   Renewal Reminder    A value of more than $630.00!

 $ 369.00

 

 

Check out all our individual modules!

 

 View Dynamic Registration

Dynamic Registration 5.0 (new release on 6/12/2013)

Need custom fields and workflow for your registration? Get all the power and ease of use to create the registration and profile management just the way you want it... more

$ 199.00

View Dynamic Forms

Dynamic Forms 4.1 (released 5/16/2012)

Whether it's for marketing, sales, contact forms, scheduling, information requests, surveys, or to simply better understand your customer needs, the possibilities for creating powerfully effective forms are now easy and endless! ... more

$ 195.00

 

Dynamic Views 3.1 (new on 2/7/2013)

Now have an easy yet feature-rich reporting module with custom defined display templates and unlimited search options from  Dynamic Forms or any data source like a table, view or custom query!  ... more

$ 169.00

 View Dynamic Login Module

Dynamic Login 4.1 (released 10/19/2011)

Add pizazz and functionality to your site login! Dynamic Login gives you custom templates, localization, redirection rules, SQL Validation, and Single SignOn. Want more? How about Facebook Connect, LinkedIN, and Twitter, too? Your login has never been so exciting!.   ... more

$ 149.00

 View Interactive User Import

Interactive User Import 3.0 (released 8/17/2011)

Interactive User Import provides you with the functionality to easily and quickly import users into DotNetNuke and Dynamic Registration, through a streamlined and well-documented wizard that includes many advanced features... more

$ 149.00

 View Dynamic User Directory

Dynamic User Directory 4.1 (released 4/26/2012)

The perfect compliment for extending your portals users and community! An essential ingredient for managing dynamic user information, is being able to sort key fields and create useful user directories and custom report information... more

$ 179.00

 View Renewal Reminder

Renewal Reminder 1.3

Renewal Reminder provides you with the functionality to setup email notifications for users that their security role will soon expire. After installing your renewal / security role reminder module you can now setup scheduled notifications to be distributed to your users... more

$ 129.99
 View Opt In Email

Opt In Email 5.0 (new on 4/17/2013)

'Relationship Building' and 'Communication' are two essential nuts and bolts for a business to prosper. This module allows you to bridge both of these and easily generate continuous awareness of your web site, products and services. Your prospects and customers will greatly appreciate this feature... more

$ 179.00

 View Tailored Text

Tailored Text 3.0

Personalization allows you to go the extra mile in communicating or connecting one to one with your clients. Leverage the power personalized content on your DotNetNuke site... more

$ 109.99
 View Stock Quote

Stock Quote 1.2

Giving your site visitors relevant information is critical. With the Data Springs Stock Module you can provide your users with up to date financial information... more

$ 109.99
 View Presentation Archive

Presentation Archive 2.0

With so much content on your web site, its important to give users an easy method for finding and retrieving content. Presentation Archive allows you to categorize, organize and present content within your DotNetNuke site for presentations, educational material, videos, and almost any document... more

$ 124.99
 View Real Estate

Real Estate 2.3

Real Estate 2.3 is a feature rich and user-friendly module that allows your portal users the ability to create real estate listings on your site... more

$ 149.99
 View Dynamic Image Rotator

Dynamic Image Rotator 3.3

Dynamic Image Rotator displays selected images and then rotates between the images using the Adobe® Flash® platform.  Several extended and optional features allow you to select the time to rotate each image, fade between images, and also display the images in either sequental or random order... more

$49.99
 View Info Pics Gallery

Info Pics Gallery

The Info Pics Gallery Module allows you to display thumbnail pictures with information to the user about each picture, along with a detailed description regarding the set of pictures and several other optional links... more

 $ 69.99
 View Testimonials Module

Testimonials

The Testimonials Module allows you to display customer testimonials on your site, as well as an easy method for users to submit testimonials about your web site, services, or products... more

 $ 49.99
 View Dynamic Info Cube

Dynamic Info Cube

Take your web site out of the box! Looking for a creative and interesting way to showcase information and content on your site? With millions of web sites offering information you need a fun way to display information and the solution is Dynamic Info Cube... more

$ 99.95
 Search Engine Optimization Cloud Module for DotNetNuke

Dynamic Tags

Nearly every web site developer would agree that search engine optimization is one of key aspects to a successful web site. Part of search engine optimization requires providing search engines that crawl your web site with appropriate and meaningful content... more

$ 69.99
 View Page Tags

Page Tags

'Page Tags' pulls in search terms that users searched to find the current page. There are many benefits to displaying these search words that delivered the user to the site, find our more details ... more

$ 59.99
 Random Rounded Images

Random Rounded Images

Random Rounded Images is an easy to use upgraded version of the images module included with DNN. With RRI, you can select multiple images to display randomly when the module loads. For example, you can add 10 images to the module, and each time you refresh or load the page one of those images will... more

$ 49.99
 View Back on Track

Back on Track

Giving your site visitors fast access to areas of interest is vital to your web site's ease of use and ultimately - sales potential... more

$ 99.99
 

Dynamic News Ticker 2.0

Dynamic News Ticker allows you to scroll through news items in a horizontal or veritical direction with administrative features that allow you to easily customize the look of your news ticker. Each instance of Dynamic News Ticker can be set up to have different sizes, scroll directions, scroll speed... more

$ 39.00
 View Quick Poll

Quick Poll

Give your users a voice, while also providing an important way for you to gather opinions from your users and measure visitors' responses to questions on your site! Polls are significant because they can provide a way for your web site visitors to share ideas and vote on topics of your choosing... more

$ 39.99
 View Flash Contacts

Dynamic Contacts 2.0

Dynamic Contacts is the fastest and easiest way you can help visitors of your website connect with your key personnel... more

$ 79.99
     

 

 

 
 

Join our mailing list...

Get current news and events the easy way
 
 
   
Subscribe Me

Recent Blogs...

 
Copyright 2005 - 2011 by Data Springs, Inc.