Getting an account by it's ID

When having an instance of MastodonHttpService, you can get an account by it's ID via the Accounts endpoint, and then either of the GetAccount or GetAccountAsync methods.

If the request is successful, an instance of MastodonAccountResponse returned representing the overall response. The Body property then holds an instance of MastodonAccount representing the response body.

@using Skybrud.Social.Mastodon.Exceptions
@using Skybrud.Social.Mastodon
@using Skybrud.Social.Mastodon.Models.Accounts
@using Skybrud.Social.Mastodon.Responses.Accounts

@{

   // Initialize a new HTTP service (basically the API wrapper)
   MastodonHttpService mastodon = MastodonHttpService
       .CreateFromDomain("umbracocommunity.social");

    try {

        // Make the request to the Mastodon API
        MastodonAccountResponse response = await mastodon.Accounts.GetAccountAsync("110661369750014952");

        // Get the account from the response body
        MastodonAccount account = response.Body;

        <pre>ID: @account.Id</pre>
        <pre>Username: @account.Username</pre>
        <pre>Display Name: @account.DisplayName</pre>

    } catch (MastodonHttpException ex) {

        <pre>@ex</pre>
        <pre>@ex.StatusCode</pre>
        <pre>@ex.Error</pre>
        <pre>@ex.Response.Body</pre>

        return;

    } catch (Exception ex) {

        <pre>@ex</pre>

        return;

    }

}

Notice that requests to the Mastodon API may fail, so it's recommended to wrap the request in a try/catch block.

Read more about error handling