Mastonet 1.0.0
See the version list below for details.
dotnet add package Mastonet --version 1.0.0
NuGet\Install-Package Mastonet -Version 1.0.0
<PackageReference Include="Mastonet" Version="1.0.0" />
paket add Mastonet --version 1.0.0
#r "nuget: Mastonet, 1.0.0"
// 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
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
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 | Versions 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. |
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 10.0.2)
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 | 221 | 1/14/2024 | |
3.1.2 | 628 | 9/19/2024 | |
3.1.1 | 1,810 | 1/14/2024 | |
3.1.0 | 300 | 12/28/2023 | |
2.3.1 | 4,275 | 4/22/2023 | |
2.3.0 | 1,361 | 3/13/2023 | |
2.2.2 | 427 | 2/5/2023 | |
2.2.1 | 951 | 1/10/2023 | |
2.2.0 | 350 | 12/24/2022 | |
2.1.0 | 290 | 12/21/2022 | |
2.0.3 | 311 | 12/19/2022 | |
2.0.2 | 1,077 | 12/4/2022 | |
2.0.1 | 390 | 11/25/2022 | |
2.0.0 | 341 | 11/21/2022 | |
1.9.0 | 2,190 | 10/21/2021 | |
1.8.2 | 412 | 4/14/2021 | |
1.8.1 | 628 | 11/30/2019 | |
1.8.0 | 723 | 9/28/2019 | |
1.7.1 | 674 | 7/13/2019 | |
1.6.0 | 672 | 6/19/2019 | |
1.5.1 | 665 | 5/24/2019 | |
1.5.0 | 710 | 4/28/2019 | |
1.4.1 | 825 | 1/28/2019 | |
1.4.0 | 1,070 | 9/23/2018 | |
1.3.1 | 969 | 8/28/2018 | |
1.3.0 | 917 | 8/26/2018 | |
1.2.0 | 1,333 | 12/1/2017 | |
1.1.0 | 1,198 | 11/23/2017 | |
1.0.0 | 1,159 | 10/25/2017 |