InstaSharp is a C# library that wraps the Instagram API and makes it easy to write applications with Instagram data.
You have two choices here until the package is available via NuGet. You can either download the compiled class library, or you can head on over to GitHub and download the Visual Studio Solution. The latter is preferred so you can fork, improve, and push your changes back in. OSS FTW.
- Getting Started
Step 1 - Sign Up
Head over to instagram.com/developer and register a new client. You will need to provide a callback URL. You can use your development server (http://localhost:
Now you should have your Client ID and Client Secret
Step 2 - Add References
Add a reference to the InstaSharp.dll to your project, as well as the Newtonsoft.Json.dll. The Newtonsoft library handles the json parsing since the support for it in .NET is less than savory.
Step 3 - Create The Config Class
You will need to store your Client ID and Client Secret somewhere in your application (or database). To begin using InstaSharp, you will need to create an instance of the InstagramConfig class. This class is needed for every endpoint that you will be using, so I would highly suggest caching that object or using an IoC container to build it.
"https://api.instagram.com/oauth", "< Your Client Id Goes Here >",
"< Your Client Secret Goes Here >", "< Your Redirect URI Goes Here >");
At this point, you can either move on to Step 4, or you can begin using the Endpoints as an unauthenticated user.
Step 4 - Authenticate
If you do not want to authenticate a user to Instagram to get access to their data, you can skip this.
You now need to authenticate with a user to Instagram. InstaSharp contains a helper for helping you create the link that you will use the access Instagram for authentication. You can use it, or you can build your own URL. For more information about composing the correct request URL, look here.
The first three parameters there are pretty self explanatory. The "scopes" parameter defines what level of access you are requesting over the user's data. You can find more information about scopes at the bottom of this page.
Step 5 - Handle Callback
You will now need to handle the authentication callback which will contain your access code. Below is a sample MVC method which handles the response from the callback and creates the AuthInfo object. You will need to cache that AuthInfo object. If you are building a website, I would suggest storing it in the session. The classes are serializable, so it shouldn't be a problem.
Session["InstaAuth"] = _instaAuth.RequestToken(code);
return RedirectToAction("Index", "Home");
You're now ready to head over to the Endpoints and start using the Instagram data.
If you have made it past the authentication, congratulations. That is easily the hardest part. There is nothing glamorous about OAuth. From here on out, it's smooth sailing.
Instagram is broken up into Endpoints. Users, Media, Locations, Relationships, Geographies, Likes, Tags and Comments.
Each endpoint has an Authenticated and an Unauthenticated class. If you are using Authenticated, you will need to pass in the InstagramConfig object as well as the AuthInfo object. If you are using the Unauthenticated class, you only need the InstagramConfig class. Remember that not all methods are available to an unauthenticated user.
Here is an example of how to retrieve a user's feed.
var result = users.Feed("self");
That's all there is to it. All of the endpoints behave exactly the same way. The responses will contain mapped .NET objects, but you can access the raw json that was returned from the instagram API by tacking .json on to the end of any result.
var result = users.Feed("self");
I urge you to spend some time looking at the Instagram Endpoints and what they return.
burkeholland at gmail dot com