Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Consuming the Stack Exchange API with C#

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...

Stack Exchange API

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:

image

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.

Table Of Contents

  • Introduction
  • API Usage
  • User Profile
  • Sending Requests
  • Reputation Changes

The post goes into some nice depth; from getting into the API;

API Usage

You can find the documentation for the Stack Exchange API here:

http://api.stackoverflow.com/

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...

image

image

And in the end, some output;

image

BTW, to download the full sample, head over to his download page;

SNAGHTML2de19398

SNAGHTML2de09c9d

SNAGHTML2de5ef6e

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...

Follow the Discussion

Remove this comment

Remove this thread

close

Comments Closed

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.