MisskeySharp is a client library for .NET applications to utilize Misskey.
This library is not an official offering by the Misskey developers.
The usage examples are as follows:
Step 1: Get a URL for authorize app page
We will prepare to obtain the access token using "MiAuth".
var misskey = new MisskeyService("https://misskey.io/");
var authUri = misskey.GetAuthorizeUri(
"サンプル (my app) " + DateTime.Now.ToString("yyyyMMdd-HHmmsss-fff"),
"https://www.a32kita.net/favicon.ico",
"https://dummy.a32kita.net/callback",
MisskeyPermissions.Write_notes | MisskeyPermissions.Read_account);
In MiAuth, you can use any value for the GetAuthorizeUri()
parameter because it allows you to set the application name, icon, and callback URL during access token acquisition.
Step 2: After the user approves the application in the browser, obtain the access token
await misskey.AuthorizeWithAuthorizeUriAsync(authUri);
// misskey.AccessToken: "98eY****************************"; <= Access Token
The obtained access token will be stored in the AccessToken
property.
If the initially obtained access token is being recorded, user approval will not be required from the second time onwards.
await misskey.AuthorizeWithAccessTokenAsync("98eY****************************");
We will post a new note. In the following example, we will post a note with the content 'hello, world!!' to the timeline for followers.
await misskey.Notes.Create(new Note()
{
Text = "hello, world!!",
Visibility = "followers",
});
Console.WriteLine("Completed: {0}", resp.CreatedNote.Id);
For the parameters specified here, please refer to the official documentation:
https://misskey-hub.net/docs/api/endpoints/notes/create.html
Retrieve a list of followed users by specifying the user ID.
Example code
var resp = await misskey.Users.Following(new UsersFollowingFollowersQuery()
{
UserId = "9arwh5oymn",
});
Console.WriteLine("Following list;");
foreach (var follow in resp)
{
Console.WriteLine(" {0} | {1}", follow.Followee.Username.PadRight(20), follow.Followee.Name);
}
Using the Streaming API to receive the timeline in real-time. Events will be triggered upon receiving new notes.
Example code
Notice: This feature is currently under verification and there is a possibility of significant specification changes in the futurevar noteReceived = new Action<MisskeyNoteReceivedEventArgs>(e =>
{
var note = e.NoteMessage.Body.Body;
if (note == null)
return;
var rn = note.Renote != null;
if (rn)
note = note.Renote;
Console.WriteLine("R {0}: (@{1}) {2}", rn ? "RENOTE" : "NORMAL", note?.User?.Username, note?.Text);
});
misskey.Streaming.NoteReceived += (sender, e) => noteReceived(e);
var st = misskey.Streaming.Connect(MisskeyStreamingChannels.HybridTimeline);
Console.ReadLine();
misskey.Streaming.Disconnect(st);
Now available on NuGet
NuGet\Install-Package MisskeySharp
MisskeySharp is designed for .NET Standard 2.0, making it available for a wide range of .NET applications.
Please refer to Microsoft's documentation for information on the targets that can apply .NET Standard 2.0 libraries:
https://learn.microsoft.com/ja-jp/dotnet/standard/net-standard?tabs=net-standard-2-0#select-net-standard-version
If you are using MisskeySharp via NuGet, it will be automatically installed.