Mastonet 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mastonet --version 1.0.0                
NuGet\Install-Package Mastonet -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mastonet" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mastonet --version 1.0.0                
#r "nuget: Mastonet, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Mastonet as a Cake Addin
#addin nuget:?package=Mastonet&version=1.0.0

// Install Mastonet as a Cake Tool
#tool nuget:?package=Mastonet&version=1.0.0                

Masto.NET

Build status NuGet

Masto.NET is a .net standard library for Mastodon written in C#.

Sample

If you prefer to browse code, you can go the the sample project : https://github.com/glacasa/Mastonet.SampleApp

Nuget

The package is available on Nuget : https://www.nuget.org/packages/Mastonet

Run the following command in the Package Manager Console :

Install-Package Mastonet

How to use

App registration

You need to obtain a ClientId and a ClientSecret for your app, directly from the client, on the target Mastodon instance. Call the static CreateApp method :

var authClient = new AuthenticationClient("instanceUrl");
var appRegistration = await authClient.CreateApp("Your app name", Scope.Read | Scope.Write | Scope.Follow);

The appRegistration object must be saved.

User login, using e-mail and password

Now you can connect the user (not recommended, prefer OAuth when you can) :

var auth = await authClient.ConnectWithPassword("email", "password");

User login, using OAuth

The recommended way to login is to use OAuth. You open a web browser and let the user login himself on his instance.

var url = authClient.OAuthUrl();
OpenBrowser(url);

You can either embed a WebView in you app, or open an external browser. When the user allowed your app to access its account, he is redirected to a web page with an auth code.

You have several option to get the code :

  • Ask the user to copy and paste it in your app (easy for you, but not user-friendly)
  • If you have embedded a WebView in your app, you can read the final page. The code is in the url, and in the webpage embedded in a <code> tag
    OAuth result

If you are in a web context, you can set the final page url, and the user will be redirected directly to your server with the code. Just add your url to the OAuthUrl method.

var url = authClient.OAuthUrl(myRedirectPage);

Now this code will let you get the access token for the user

var auth = await authClient.ConnectWithCode(authCode);

Connect with existing authentication token

When you have the access token, you should save it in the app, and use it every time you restart the app. You just need to add it to the MastodonClient constructor.

var client = new MastodonClient(appRegistration, auth);

Now you can call all the API methods. See Mastodon API overview

Streaming

You can use the TimelineStreaming to be notified for every status, notification and deletion on a timeline.

var client =  new MastodonClient("instance", appRegistration, auth);
var streaming = client.GetUserStreaming();

// Register events
streaming.OnUpdate = OnStatusReceived;
streaming.OnNotification = OnNotificationReceived;
streaming.OnDelete = OnDeleteReceived;

// Start streaming
streaming.Start();


// ...

// Stop streaming
streaming.Stop();

Connection issues with .net framework

Some instances only accept TLS 1.2 requests, but .net Framework only support TLS 1.2 by default on version 4.6 and above If you are on version 4.5.2 or earlier, you should force using TLS 1.2 by this line of code before any request :

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Mastonet:

Package Downloads
VL.IO.Mastonet

Support for the Mastodon API

VL.HDE

Provides access to the vvvv UI API

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0-preview0 223 1/14/2024
3.1.2 660 9/19/2024
3.1.1 1,812 1/14/2024
3.1.0 302 12/28/2023 3.1.0 is deprecated because it has critical bugs.
2.3.1 4,296 4/22/2023
2.3.0 1,363 3/13/2023
2.2.2 429 2/5/2023
2.2.1 953 1/10/2023
2.2.0 352 12/24/2022
2.1.0 292 12/21/2022
2.0.3 313 12/19/2022
2.0.2 1,081 12/4/2022
2.0.1 392 11/25/2022
2.0.0 343 11/21/2022
1.9.0 2,195 10/21/2021
1.8.2 414 4/14/2021
1.8.1 630 11/30/2019
1.8.0 727 9/28/2019
1.7.1 676 7/13/2019
1.6.0 674 6/19/2019
1.5.1 667 5/24/2019
1.5.0 712 4/28/2019
1.4.1 827 1/28/2019
1.4.0 1,072 9/23/2018
1.3.1 971 8/28/2018
1.3.0 919 8/26/2018
1.2.0 1,335 12/1/2017
1.1.0 1,200 11/23/2017
1.0.0 1,161 10/25/2017