Twitter From ASP.NET – Friends vs Followers

F03I0051 If you want to emulate the services of something like Twitter Karma you are going to need to learn how to retrieve your list of friends and followers.

What makes this especially difficult is that the documentation for this on both the Twitterizer site (where it is practically non-existent) and on the Twitter site (where it is not exactly accurate) makes figuring out this process particularly difficult.

The two main elements you need to be aware of prior to writing the code to retrieve your list of friends or followers is that you can only retrieve 100 friends or followers at a time and that you need to specify which page of followers you are looking for by passing a parameter.  Hopefully just knowing this will save you the hours of searching I had to do to find this information.

One other thing that might be useful when you have a lot of friends or followers is this final bit of information.  You can only make 100 API calls an hour.  This means that you can only retrieve 100 * 100 (10,000) friends or followers at a time and you’ll need to get a waiver from Twitter so you can make more API requests.

So, on to the code.  I’m going to concentrate on retrieving friends.  The followers code is similar.

As I mentioned, you’ll need to pass a parameter.  All parameters in Twitterizer are objects of type TwitterParameter.  We want to create a Twitter parameter that holds the page number.  The code for that looks like this:

TwitterParameters param = new TwitterParameters();
param.Add(TwitterParameterNames.Page, page);

where page is an integer starting at the number one.

Then we call the method to return that page of 100 friends


TwitterUserCollection fc = twit.User.Friends(param);

where twit is a Twitter object created by passing in the username and password as we’ve done in previous posts about twitter.

The rest of your code will then do something with that information by retrieving each TwitterUser object from the collection and doing something with it, like putting it in a database.

foreach (TwitterUser u in fc)
{
    // Do something with the TwitterUser here
}

If you are storing the user information, I’d use the TwitterUser.ID rather than the TwitterUser.UserName or TwitterUser.ScreenName.  Both the UserName and ScreenName can and probably will change for an account, but the ID will remain constant.


Other Related Items:

Beginning ASP.NET 4: in C# and VB (Wrox Programmer to Programmer)Beginning ASP.NET 4: in C# and VB (Wrox Programmer to Programmer)This book is for anyone who wants to learn how to build rich and interactive web sites that run on the Microsoft platform. With the knowledge you gain... Read More >
A-Line Plaid Short Skirt with Matching Patent Belt (Choose Black or Purple) - Clearance Sale !A-Line Plaid Short Skirt with Matching Patent Belt (Choose Black or Purple) - Clearance Sale !This versatile skirt can be dressed up or down. Pair with a sexy blouse and heels for a night on the town or pair with a cardigan, flats and tights fo... Read More >
All Natural Dog Treats - Liver - 16 oz Resealable BagAll Natural Dog Treats - Liver - 16 oz Resealable BagWe want you to feel good about the treats you give your special dog. Charlee Bear Dog Treats are made with real liver for a taste dogs love. All natu... Read More >

Related Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor