yoni56.InstagramSharpSdk
1.0.3
dotnet add package yoni56.InstagramSharpSdk --version 1.0.3
NuGet\Install-Package yoni56.InstagramSharpSdk -Version 1.0.3
<PackageReference Include="yoni56.InstagramSharpSdk" Version="1.0.3" />
<PackageVersion Include="yoni56.InstagramSharpSdk" Version="1.0.3" />
<PackageReference Include="yoni56.InstagramSharpSdk" />
paket add yoni56.InstagramSharpSdk --version 1.0.3
#r "nuget: yoni56.InstagramSharpSdk, 1.0.3"
#:package yoni56.InstagramSharpSdk@1.0.3
#addin nuget:?package=yoni56.InstagramSharpSdk&version=1.0.3
#tool nuget:?package=yoni56.InstagramSharpSdk&version=1.0.3
InstagramSharp
A simple, strongly-typed C# SDK that wraps Instagram's Graph API, built for .NET 10. InstagramSharp makes it easy to authenticate with Instagram, and to work with users, media, comments, hashtags, insights, stories, mentions, business discovery, messaging, and content publishing — all through a clean, testable, interface-based API.
Features
- OAuth authentication — build authorization URLs, exchange codes for tokens, and manage short-/long-lived token exchange & refresh.
- Users — fetch user profile information.
- Media — get single media items or list a user's media.
- Comments — create, get, list, delete comments, and manage replies.
- Hashtags — search hashtags, get hashtag info, recent/top media for a hashtag.
- Insights — retrieve account-level and media-level insights/metrics.
- Stories — retrieve a user's active stories.
- Mentions — get mentioned comments/media and reply to mentions.
- Business Discovery — look up public business/creator account data and send messages.
- Publishing — create media containers, check container status, and publish content.
- Container — inspect container objects.
The library is organized as one interface (I*) and one implementation (T*) per feature area, all exposed through a single IInstagramClient entry point.
Installation
InstagramSharp is distributed as a NuGet package:
dotnet add package yoni56.InstagramSharpSdk
Requirements
- .NET 10 (or a compatible target framework)
- A Meta/Instagram Graph API access token (and, for OAuth flows, an app ID, app secret, and redirect URI)
Getting Started
Create a client
using InstagramSharp;
var client = new InstagramClient("YOUR_ACCESS_TOKEN");
InstagramClient implements IInstagramClient and exposes each feature area as a property:
public interface IInstagramClient
{
IUsers Users { get; }
IMedia Media { get; }
IComments Comments { get; }
IInsights Insights { get; }
IStories Stories { get; }
IHashtags Hashtags { get; }
IPublishing Publishing { get; }
IMentions Mentions { get; }
IBusinessDiscovery BusinessDiscovery { get; }
IMessaging Messaging { get; }
InstagramOAuth CreateInstagramOAuth(string appId, string appSecret, string redirectUri);
}
Internally, the client targets the Facebook Graph API at https://graph.facebook.com/v23.0 and automatically attaches your access token to every request.
Example: Get user info
var response = client.Users.Get(new UserGetRequest
{
// request properties, e.g. UserId / Fields
});
if (response.IsSuccessful)
{
var user = response.Data;
}
Example: List media
var response = client.Media.List(new MediaListRequest
{
// request properties
});
Example: Publish content
// 1. Create a media container
var container = client.Publishing.Create(new ContainerCreateRequest
{
// e.g. ImageUrl, Caption, etc.
});
// 2. Check container status
var status = client.Publishing.Get(new ContainerStatusRequest
{
// container id
});
// 3. Publish the container
var published = client.Publishing.Publish(new PublishRequest
{
// container id
});
Every call returns a RestResponse<T> (from RestSharp), so you can inspect IsSuccessful, StatusCode, Content, and the strongly-typed Data payload.
OAuth Authentication Flow
InstagramSharp includes an InstagramOAuth helper for handling the full Instagram Basic Display / Graph OAuth flow:
using InstagramSharp;
var oauth = client.CreateInstagramOAuth(appId: "APP_ID", appSecret: "APP_SECRET", redirectUri: "https://yourapp.com/callback");
// 1. Redirect the user to the authorization URL
string authUrl = oauth.BuildAuthorizationUrl(scope: "user_profile,user_media,user_insights");
// 2. Exchange the returned "code" for a short-lived access token
var tokenResponse = await oauth.ExchangeCodeForTokenAsync(code);
// 3. Exchange the short-lived token for a long-lived token
var longLivedToken = await oauth.ExchangeShortLivedForLongLivedTokenAsync(tokenResponse.AccessToken);
// 4. Refresh a long-lived token before it expires
var refreshedToken = await oauth.RefreshLongLivedTokenAsync(longLivedToken.AccessToken);
If a request fails, an AuthException is thrown containing the error message and raw response content.
Project Structure
src/
├── BusinessDiscovery/ # Public account discovery + messaging
├── Comments/ # Comment CRUD, replies, listing
├── Container/ # Media container inspection
├── Hashtags/ # Hashtag search & media
├── Insights/ # Account & media insights
├── Media/ # Media get/list
├── Mentions/ # Mentioned comments/media, mention replies
├── OAuth/ # InstagramOAuth authentication flow
├── Publishing/ # Container create/status + publish
├── Stories/ # Active stories retrieval
├── Users/ # User profile retrieval
├── IInstagramClient.cs # Main client interface
└── InstagramClient.cs # Main client implementation
Each feature folder follows the same convention:
I<Feature>.cs— public interface describing available operationsT<Feature>.cs— concrete implementation usingRestSharpModels/Request/— strongly-typed request modelsModels/Response/— strongly-typed response models
Dependencies
- RestSharp — HTTP client used for all API calls
- Newtonsoft.Json — JSON serialization
- Nito.AsyncEx.Context — async context utilities
- SimpleInjector — dependency injection support
License
This project is licensed under the MIT License.
Repository
Source code is hosted on GitHub: ydahan56/InstagramSharp
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Newtonsoft.Json (>= 13.0.5-beta1)
- Nito.AsyncEx.Context (>= 5.1.2)
- RestSharp (>= 114.0.1-alpha.0.4)
- SimpleInjector (>= 5.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.