Instagram
While the Instagram API mainly focuses on media, is also has methods for accessing locations, users and similar.
The Instagram API is divided into multiple endpoints serving different purposes - eg. media, users and locations. Skybrud.Social follows the same structure as the API, so head over to the list of endpoints for more information. This is also where you will find examples for the various endpoints / methods in the Instagram API.
Structure
The Instagram API is divided into multiple endpoints serving different purposes - eg. media, users and locations. Skybrud.Social follows the same structure as the API, so head over to the list of endpoints for more information. This is also where you will find examples for the various endpoints / methods in the Instagram API.
Authentication
To get data from the Instagram API, you either need an access token (on behalf of a user) or a client ID (on behalf of your app). Information about obtaining either of these can be found on the authentication page.
Rate limiting
The Instagram API enforces rate limiting - meaning that you can only make a certain amount of request over a given time. Most methods have rather high limit, while a few methods has a very low limit. Instagram.com has a good description of limits.
Making calls to the API
To make requests to the Instagram API, you must initialize an instance of the InstagramService
class. As described on the authentication page, you should obtain an access token to access the API on behalf of your users.
So to initialize the class using an obtained access token, your code could look as:
InstagramService service = InstagramService.CreateFromAccessToken(accessToken);
The InstagramService
class builds on top of the InstagramClient
class, so you can also specify an instance of this class instead:
InstagramService service = InstagramService.CreateFromOAuthClient(new InstagramOAuthClient {
AccessToken = accessToken
});
The InstagramService
class then has properties for each supported endpoint. As an example, you can get information about the authenticated user as:
InstagramUserResponse response = service.Users.GetSelf();
InstagramUser user = response.Body.Data;
You can find a list of all supported endpoints at the the endpoints page.
Error handling
If you make a request to the Instagram API, and the server responds with an error, you can handle this by catching exception of the type InstagramException
. An example of an error returned by the API, is if you make a request for a user that doesn't exist. You you make a request with an invalid access token or client ID, this will also trigger an error.
Some errors/exceptions are represented by their own exception class (extending theInstagramException
class). These are currently:
InstagramNotFoundException
InstagramOAuthException
InstagramOAuthAccessTokenException