• InstaAPI

InstaAPI is a CSharp(#) wrapper for Instagram API build in DotNET Framework 4. It is a simple, small library that uses Instagram's server-side flow for fetching access tokens.


  • Quick Note

Started working on it when I couldn't find a simple C# API for Instagram.
The API may contain some bugs; feel free to raise issues regarding the same. You can also contact me via 

    • email: yuvrajbabrah@live.com
    • facebook: fb.com/yuvraj.babrah
    • twitter: @yuvrajb

Yuvraj Singh Babrah, 2015


  •  Important

In order to post or delete something on Instagram using any API, you first need to get your application approved from Instagram. In case if you try to mention anything besides basic in your scopes you'll encounter an error on the authentication page. [More on this: Instagram Contact]

You won't face any hiccup while fetching any type of data; be it media, likes or comment.


  •  Requirements
  1. DotNet Framework 4 or above
  2. Newtonsoft json library

  •  Quick Walkthrough

Refer the following quick-guide for using the API:

Creating InstaConfig Object (to be used for both authenticated and unauthenticated requests):

List<Scope> scopes = new List<Scope>() { Scope.basic, Scope.relationships, Scope.likes };
InstaConfig config = new InstaConfig("CLIENT_ID", "CLIENT_SECRET", "REDIRECT_URI", scopes);

// use this to redirect user for authenticating your application
String AuthenticationUriString = config.GetAuthenticationUriString();


Creating OAuth Object (to be used for authenticated requests):

OAuth oauth = new OAuth(config, "CODE_ATTACHED_WITH_REDIRECTEDURI_AFTERSUCCESSFUL_AUTHENTICATION");
AuthUser user = oauth.GetAuhtorisedUser();

Console.WriteLine(user.AccessToken);
Console.WriteLine(user.UserId);
Console.WriteLine(user.UserName);
Console.WriteLine(user.FullName);

You can serialize and save the AuthUser object. This is how you can save the access for the authorized user; hence, there will be no need to re-authorize the application.

Fetching User Feeds:

Users CurrentUser = new Users(config, user);
Feeds feeds = CurrentUser.GetUserPosts("1118571892", new GetUserPostsParameters());
foreach (var fd in feeds.Data)
{
Console.WriteLine(fd.Caption.Text);
Console.WriteLine(fd.Images.StandardResolution.url);
Console.WriteLine(fd.User.UserName);
}


Fetching Comments:

Comments comm = new Comments(config, user);
MediaComments mc = comm.GetMediaRecentComments("662323776542578144_1118571892");
foreach (var comment in mc.Data)
{
Console.WriteLine(comment.From.UserName);
Console.WriteLine(comment.Text);
}


Posting a Commment:

Comments comm = new Comments(config, user);
MetaData meta = comm.PostMediaComment("662323776542578144_1118571892", "i am a comment from github docs");
Console.WriteLine(meta.Code);


I'm sorry for not having a proper html type documentation. Wish Visual Studio could have some easy mechanism as provided in Netbeans. In the mean time, happy coding!

 

 

Last edited Aug 24, 2015 at 6:22 PM by yuvrajb, version 23