Skip to content

cucmberium/TootNet

Repository files navigation

TootNet

NuGetBadge

日本語のREADMEはこちら

TootNet is a Mastodon library for .NET Standard.

This library is designed to intuitively access the API in the same way as the Twitter library CoreTweet.

Sample

For basic usage, please refer to the Demo.

Also, the test code provides simple usage for all APIs.

Since TootNet is almost compatible with the official API, the official documentation is also a useful reference.

Authorizing:

// Create new app
var authorize = new Authorize();
await authorize.CreateApp("mstdn.jp", "yourclientnamehere", Scope.Read | Scope.Write);

// Authorize with code
var authorizeUrl = authorize.GetAuthorizeUri();
Console.WriteLine(authorizeUrl);
var code = Console.ReadLine().Trim();
var tokens = await authorize.AuthorizeWithCode(code);

Tooting:

using (var fs = new FileStream(@"./picture.png", FileMode.Open, FileAccess.Read))
{
    // toot with picture
    var attachment = await tokens.MediaAttachments.PostAsync(file => fs);
    await tokens.Statuses.PostAsync(status => "test toot", visibility => "private", media_ids => new List<long>() { attachment.Id });
}

Getting timelines:

var statuses = await tokens.Timelines.HomeAsync(limit => 10);

foreach (var status in statuses)
    Console.WriteLine(status.Content);

Streaming using reactive extensions:

var observable = tokens.Streaming.UserAsObservable();
var disposable = observable.Subscribe(x =>
{
    switch (x.Type)
    {
        case StreamingMessage.MessageType.Status:
            Console.WriteLine(x.Status.Account.Acct + x.Status.Content);
            break;
    }
});

await Task.Delay(TimeSpan.FromSeconds(30));
disposable.Dispose();

Platforms

  • .NET Standard

License

This software is licensed under the MIT License.

This library uses part of the codes of the following libraries.

Other

Pull requests are welcome!