Skip to content
develop
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NuGet License

Mastodon API client library for C#

The Mastodon API Client Library for C# (PCL 4.5, Profile 111)

Pull reqeusts are always welcome!

master branch

AppVeyor status Travis Status

develop branch

AppVeyor status Travis Status

Install

Install-Package Mastodon.API

Registering an app to Mastodon instance

var authClient = new MastodonAuthClient(new Uri("https://friends.nico"));
var redirectUri = new Uri("urn:ietf:wg:oauth:2.0:oob");
var scope = OAuthAccessScope.of(OAtuhAccessScopeType.Read);
var app = await authClient.CreateApp("client_name", redirectUri, scope);

A registered OAuth application is assigned a unique Client ID and Client Secret.

Login with email address and password

Not recommended to use in service. The Authorization Code Grant flow is recommended for applications.

var token = await authClient.GetOAuthToken(app.ClientId, app.ClientSecret, "username", "password", scope);

Making API Calls

var config = new MastodonApiConfig(instanceUrl, token.AccessToken);
var api = new MastodonApi(config);
var account = await api.GetCurrentAccount();

Error Handling

All error responses are thrown as the type MastodonApiException. Please be sure to catch this in your code and respond to any error condtions appropriately.

try
{
  // api calls here
}
catch (MastodonApiException e)
{
  // error handling here (i.e., no results found, login failed, server error, etc)
}

License

MIT

Author

gomi_ningen (@53ningen)