Consuming the Stack Exchange API with C#
- Posted: Oct 19, 2011 at 6:00 AM
- 11,066 Views
- 2 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Need I say anything about the awesome that is Stack Overflow? Okay, maybe adding a walk-through of consuming its API with C# needs to be said...
Two weeks ago I was playing around with the Stack Exchange API to see if it was easy to build a custom flair application. You know, this little guy:
How hard can it be to retrieve a user’s profile, badge count and reputation updates? Surely, Stack Exchange has an API. And they do…and it’s pretty easy to use. Let’s quickly cobble together a small sample application.
- Introduction
- API Usage
- User Profile
- Sending Requests
- Reputation Changes
The post goes into some nice depth; from getting into the API;
You can find the documentation for the Stack Exchange API here:
At the time of writing the latest release is v1.1, but a draft specification for version 2.0 has just been released.
What do you need to know about the API?
- It’s read-only
- All API responses are JSON
- All responses are GZIP’d
- API usage is throttled by IP address
To the tools/libraries you'll need;
So what do we need to be able to use the API?
- It talks JSON? Fire up NuGet and get the popular Json.NET library.
- We’ll need to issue requests. Let’s keep it simple and use the HttpWebRequest class
- All responses are GZIP’d? Luckily the .NET framework provides us with the GZipStream class.
To writing code...
And in the end, some output;
BTW, to download the full sample, head over to his download page;
So if you're interested in the Stack Overflow/Stack Exchange API, or just consuming a web service API that uses JSON, this project is waiting for you...
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Nice one
Thanks Greg. Nice summary.
Regards,
Christophe
Remove this comment
Remove this thread
close