Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 20 hours 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 (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2017-07-05T11:40:52.000Z (over 7 years ago)
- Last Synced: 2024-04-13T14:04:38.348Z (7 months ago)
- Topics: csharp, mastodon
- Language: C#
- Homepage: https://github.com/tootsuite/mastodon
- Size: 131 KB
- Stars: 26
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![NuGet](https://img.shields.io/nuget/v/Mastodon.API.svg)](https://www.nuget.org/packages/Mastodon.API) [![License](https://img.shields.io/cocoapods/l/BadgeSwift.svg?style=flat)](/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](https://ci.appveyor.com/api/projects/status/qvfycjbddgbn2oxk?svg=true)](https://ci.appveyor.com/project/53ningen/mastodon-api-cs) [![Travis Status](https://travis-ci.org/pawotter/mastodon-api-cs.svg?branch=master)](https://travis-ci.org/pawotter/mastodon-api-cs)
#### develop branch
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/qvfycjbddgbn2oxk/branch/develop?svg=true)](https://ci.appveyor.com/project/53ningen/mastodon-api-cs/branch/develop) [![Travis Status](https://travis-ci.org/pawotter/mastodon-api-cs.svg?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)