Instagram Getting information about a user

Getting information about a user

The Users endpoint exposes a GetUser method that lets you get information about a given user based on their user ID.

It is not possible to get information about a user based on their username directly, so you will instead have to search for their username, and then get the user ID from the search results.

The GetUser method will return an object representing the entire HTTP response from the API, so have a look at the example on how to get the information of the user via the InstagramUser instance:

@using Skybrud.Social.Instagram.Objects.Users
@using Skybrud.Social.Instagram.Responses.Users
@inherits WebViewPage<Skybrud.Social.Instagram.InstagramService>

@{

    // Make the call to the API
    InstagramGetUserResponse response = Model.Users.GetUser(189413627);

    // Get the user object (the "Data" property matches the JSON)
    InstagramUser user = response.Body.Data;
    
    // Print some information about user
    <p>Id: @user.Id</p>
    <p>Name: @(user.HasFullName ? user.FullName : user.Username)</p>

}

Getting information about the authenticated user

If you need to get information about the authenticated user, and doesn't know his/her user ID, you can use the GetSelf method in instead:

@using Skybrud.Social.Instagram.Objects.Users
@using Skybrud.Social.Instagram.Responses.Users
@inherits WebViewPage<Skybrud.Social.Instagram.InstagramService>

@{

    // Make the call to the API
    InstagramGetUserResponse response = Model.Users.GetSelf();

    // Get the user object (the "Data" property matches the JSON)
    InstagramUser user = response.Body.Data;

    // Print some information about user
    <p>Id: @user.Id</p>
    <p>Name: @(user.HasFullName ? user.FullName : user.Username)</p>

}

Both the GetUser and GetSelf methods will return an instance of InstagramUserResponse. As you can see in the example above, this class will expose information about the user through the InstagramUser class.