Getting statuses of an account
The example below illustrates how to get the 40 most recent statuses of the umbraco
account:
@using Skybrud.Social.Mastodon.Exceptions
@using Skybrud.Social.Mastodon
@using Skybrud.Social.Mastodon.Responses.Statuses
@{
// Initialize a new HTTP service (basically the API wrapper)
MastodonHttpService mastodon = MastodonHttpService
.CreateFromDomain("umbracocommunity.social");
try {
// Make the request to the Mastodon API
MastodonStatusListResponse response = await mastodon.Accounts
.GetStatusesAsync("110661369750014952");
// Iterate through the first 40 statuses
foreach (var status in response.Body) {
<pre>@status.CreatedAt - @status.Account.DisplayName</pre>
<pre>@status.Content</pre>
<hr />
}
} 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 the ID of the account is passed to the GetStatusesAsync
. For more advanced requests - eg. for pagination or for excluding certain statuses - an instance of MastodonGetAccountStatusesOptions
may be specified instead:
@using Skybrud.Social.Mastodon.Exceptions
@using Skybrud.Social.Mastodon
@using Skybrud.Social.Mastodon.Options.Accounts
@using Skybrud.Social.Mastodon.Responses.Statuses
@{
// Initialize a new HTTP service (basically the API wrapper)
MastodonHttpService mastodon = MastodonHttpService
.CreateFromDomain("umbracocommunity.social");
try {
// Initialize the options for the request
MastodonGetAccountStatusesOptions options = new() {
Id = "110661369750014952",
ExcludeReplies = true,
ExcludeReblogs = true
};
// Make the request to the Mastodon API
MastodonStatusListResponse response = await mastodon.Accounts
.GetStatusesAsync(options);
// Iterate through the first 40 statuses
foreach (var status in response.Body) {
<pre>@status.CreatedAt - @status.Account.DisplayName</pre>
<pre>@status.Content</pre>
<hr />
}
} 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;
}
}