https://github.com/pawotter/mastodon-api-cs
The Mastodon API Client Library for C#
https://github.com/pawotter/mastodon-api-cs
csharp mastodon
Last synced: 3 months ago
JSON representation
The Mastodon API Client Library for C#
- Host: GitHub
- URL: https://github.com/pawotter/mastodon-api-cs
- Owner: pawotter
- License: mit
- Created: 2017-04-20T18:31:03.000Z (about 8 years ago)
- Default Branch: develop
- Last Pushed: 2017-07-05T11:40:52.000Z (almost 8 years ago)
- Last Synced: 2025-04-10T06:05:46.399Z (3 months ago)
- Topics: csharp, mastodon
- Language: C#
- Homepage: https://github.com/tootsuite/mastodon
- Size: 131 KB
- Stars: 28
- Watchers: 4
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/Mastodon.API) [](/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
[](https://ci.appveyor.com/project/53ningen/mastodon-api-cs) [](https://travis-ci.org/pawotter/mastodon-api-cs)
#### develop branch
[](https://ci.appveyor.com/project/53ningen/mastodon-api-cs/branch/develop) [](https://travis-ci.org/pawotter/mastodon-api-cs)
# Install
```
Install-Package Mastodon.API
```# Registering an app to Mastodon instance
```csharp
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.
```csharp
var token = await authClient.GetOAuthToken(app.ClientId, app.ClientSecret, "username", "password", scope);
```# Making API Calls
```csharp
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.
```csharp
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)