by Keyvan Nayyeri via Keyvan Nayyeri on 8/30/2006 6:28:00 PM
Some ages ago, when new FeedBurner site had been launched, I wanted to write a component for FeedBurner APIs in .NET but we know "Tomorrow is far away"!
Now FeedBurner is a famous site and many users use their services around the web. When Scott Watermasysk opened a feature item for Community Server to add external feed functionality to Community Server 2.1, I commented for him about category feeds and he replied back we should assume this feature just for main feeds. The necessity to have something to deal with FeedBurner APIs in some cases I've seen, bit me to write a component for .NET community. Hope it helps developers to manipulate their feeds on FeedBurner on fly.
FeedBurner APIs are rich enough to help every developer to deal with account feeds easily. FeedBurner is written with PHP and some APIs are a bit confusing specially when you must pass an XML file through query!!
However, I started writing this component to implement all FeedBurner APIs in .NET. I've coded this component with C# 2.0 and used .NET 2.0 new features in many parts so it's not possible to apply it in .NET 1.x. On the other hand as I used WebClient object to Get or Post to FeedBurner server, probably you can't use this component under medium trust level in ASP.NET 2.0.
Most of the code implementation is around XML manipulation and reading the source code can be a good practice for those who want to learn more about XML in .NET. Talking about source code is out of scope of this blog post and I just show how can you use this component. You can view the source code from download package to find more about it.
This component throws appropriate exceptions for any pre-defined exception on FeedBurner and returns exception messages from what FeedBurner provides. List of some standard FeedBurner errors can be found here.
My component has self explanatory classes, objects and methods. To make things clear I give some samples in this post.
To work with my component, you need to create an instance of User object and set its username and password via constructor or its properties. Although it's not necessary to create a User object to use my component but I recommend it because it saves you from passing credentials via each and every operation.
// Create a user and set its credentials via constructor
User user = new User("Username", "Password");
// Create a user and set its properties
User user2 = new User();
user2.Username = "Username";
user2.Password = "Password";
All six operations that my component supports have several overloads to get a Feed object or feed ID and feed Uri together.
To add a new feed, you should provide all properties for a Feed object after creating a new instance but leave the ID as null (although if you set it, no problem will occur) and call one of Feeds.Add() method overloads. Result of this method is a Feed object but it just has three properties available: ID, Title and Uri.
Feed feed = new Feed();
feed.Title =
"Keyvan Nayyeri's posts about .NET";
feed.Uri = "KeyvanNayyeri/DotNet";
feed.Url =
"http://nayyeri.net/rss.aspx?Tags=.NET&AndTags=1";
Service service = new Service("BrowserFriendly");
service.Parameters.Add("style", "clear");
service.Parameters.Add("message", null);
feed.Services.Add(service);
Feed result = Feeds.Add(user, feed);
Console.WriteLine("ID: " + result.ID.ToString());
Console.WriteLine("Uri: " + result.Uri);
Console.WriteLine("Title: " + result.Title);
The process for modifying a feed is very similar to add as feed by calling Feeds.Modify() method except that if you want to change the Uri of a feed, must provide its ID.
You can also simply get the list of defined feeds for a specific user by calling Feeds.Find() method. This method will return a List<Feed> but don't forget that Feed objects won't have all properties available as same as the result of Feeds.Add() or Feeds.Modify() methods.
foreach (Feed feed in Feeds.Find(user))
{
Console.WriteLine("ID: " + feed.ID.ToString());
Console.WriteLine("Uri: " + feed.Uri);
Console.WriteLine("Title: " + feed.Title);
Console.WriteLine();
}
Also you can get all details of a specific feed by passing its ID, Uri or a Feed object that contains these properties to Feeds.Get() method. This method returns a Feed object with all properties available.
Feed feed = Feeds.Get(user, "KeyvanNayyeri/DotNet");
Console.WriteLine("Url: " + feed.Url);
if (feed.Services.Count > 0)
foreach (Service service in feed.Services)
Console.WriteLine(" (Service) Name: "
+ service.Name);
if (service.Parameters.Count > 0)
foreach (KeyValuePair<string, string>
parameter in service.Parameters)
Console.WriteLine
(" (Parameter) Name: " +
parameter.Key + " Value: " +
parameter.Value);
To delete or resync a feed, you can call Feeds.Delete() or Feeds.Resync() methods. They don't return anything.
Feeds.Delete(user, feed);
Console.WriteLine("Specific feed has been removed.");
Note that some operations may take time to be shown on FeedBurner website.
I put a sample Windows Console application in download package to show how to use my component APIs. This is the output of my sample Console Application:
And this is what my feed looks like after adding it via APIs:
FeedBurner APIs component for .NET 2.0 is available here with source code.
Original Post: FeedBurner APIs component for .NET 2.0
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.