The Mastodon API Client Library for C# (PCL 4.5, Profile 111)
Pull reqeusts are always welcome!
Install-Package Mastodon.API
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.
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);
var config = new MastodonApiConfig(instanceUrl, token.AccessToken);
var api = new MastodonApi(config);
var account = await api.GetCurrentAccount();
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)
}
MIT
gomi_ningen (@53ningen)