{"id":15036314,"url":"https://github.com/yamachu/mastodot","last_synced_at":"2025-08-02T16:33:48.213Z","repository":{"id":79718996,"uuid":"88784824","full_name":"yamachu/Mastodot","owner":"yamachu","description":"C# Library for Mastodon API. Easy Toot!","archived":false,"fork":false,"pushed_at":"2023-02-10T07:58:38.000Z","size":65,"stargazers_count":25,"open_issues_count":5,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-13T13:50:03.984Z","etag":null,"topics":["csharp","csharp-library","mastodon","mastodon-apis"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yamachu.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-04-19T19:50:58.000Z","updated_at":"2024-02-16T12:05:50.000Z","dependencies_parsed_at":"2023-03-08T01:15:52.559Z","dependency_job_id":null,"html_url":"https://github.com/yamachu/Mastodot","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.037735849056603765","last_synced_commit":"646e9c10e2bdfcba7248da230cf62fe066b1f45b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamachu%2FMastodot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamachu%2FMastodot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamachu%2FMastodot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yamachu%2FMastodot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yamachu","download_url":"https://codeload.github.com/yamachu/Mastodot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126918,"owners_count":21052099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-library","mastodon","mastodon-apis"],"created_at":"2024-09-24T20:30:46.436Z","updated_at":"2025-04-09T23:23:36.142Z","avatar_url":"https://github.com/yamachu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mastodot - Mastodon API library for C# (.NET)\n\n [![NuGetBadge](https://img.shields.io/nuget/v/Mastodot.svg)](https://www.nuget.org/packages/Mastodot)\n\n\nMastodot は C# .NET Standard 1.1 および 1.3 で開発されている Mastodon API にアクセスするためのライブラリです．\nその他に 画像投稿 や 各種トークンの保存，読み込み(予定) の機能も提供しています．\n\n## 使用例\n\nトークンの取得，トゥート，ストリームへの接続 の例を一つのアプリケーションに実装している完全なコードは example ディレクトリを参照してください．\n\n## 使い方\n\n### Mastodon Instance へのアプリケーションの登録\n\nMastodon の API を使用するには ClientID と ClientSecret が必要になるため，その取得を行います．\n\n本ライブラリでは `ApplicationManager` クラスの `RegistApp` メソッドを通して行います．\n\n```csharp\n\nvar registeredApp = await ApplicationManager.RegistApp(\"Host name\", \"Your Application Name\", Scope.Read | Scope.Write | Scope.Follow);\n\n```\n\nここで得られた `Entities.RegisteredApp` クラスのインスタンスである `registeredApp ` に ClientID や ClientKey などの情報が含まれているため，`MastodonJsonConverter` クラスの `TrySerialize` メソッドなどでシリアライズしたものをファイルに保存するなどを行ってください．\n\n### アクセストークンの取得\n\nアクセストークンの取得には 2種類 方法があり，\n\n* このライブラリを通して登録に使用したメールアドレスとパスワードを使用して取得\n* ブラウザでログインした後特定のURLに飛ぶことで認可し取得\n\nが可能です．\n\n#### メールアドレスを使用\n\n```csharp\n\nvar tokens = ApplicationManager.GetAccessTokenByEmail(registeredApp, \"Email\", \"Password\");\n// RegisteredApp インスタンスがなくてもトークンを覚えているのであれば以下も可\nvar tokens = ApplicationManager.GetAccessTokenByEmail(\"Host name\", \"ClientID\", \"ClientSecret\", Scope, \"Email\", \"Password\");\n\n```\n\n#### OAuth を使用\n\n```csharp\n\nvar url = ApplicationManager.GetOAuthUrl(registeredApp);\n// ブラウザなどでこの URL にアクセスし，表示された文字列をコピーするなどして取得\n\nvar tokens = await ApplicationManager.GetAccessTokenByCode(registeredApp, \"Code that Browser shows\");\n\n```\n\n### アクセストークンを使用した Mastodon API へのアクセス\n\n以上で得られた `Entities.TokenInfo` クラスのインスタンスである `tokens` のメンバの `AccessToken` を使用して Mastodon の API を使用します．\n\nそのためのクライアントは\n\n```csharp\n\nvar client = new MastodonClient(\"Host name\", \"AccessToken\");\n\n```\n\nで生成することが出来ます．\n\n#### Toot してみる\n\nToot するには `PostNewStatus` メソッドを通して行います．\n\n```csharp\n\nclient.PostNewStatus(status: \"Hello Mastodon!\");\n// 画像つきで行うのであれば\nvar attachment = await client.UploadMedia(\"File Path\");\nclient.PostNewStatus(\"Look my cuuuuute dog!\", mediaIds: new int[]{attachment.Id});\n\n```\n\nのようにして行うことが可能です．\n\n#### ストリーム API を使う\n\nMastodon では Twitter の用にタイムラインなどのストリームを扱うことが出来ます．\n\nこのストリームを扱う場合は以下のように行います．\n\n```csharp\n\nvar publicStream = client.GetObservablePublicTimeline()\n                    .OfType\u003cStatus\u003e()\n                    .Subscribe(x =\u003e Console.WriteLine($\"{x.Account.FullUserName} Tooted: {x.Content}\"));\n\n```\n\n`GetObservable{User, Public, Hashtag}Timeline` は `IObservable\u003cIStreamEntity\u003e` を返すので Subscribe して Stream の情報を取得します．\n\nこのためストリームを扱う際は `System.Reactive` を使用することをおすすめします(Nuget などで導入してください)．\n`IObserver\u003cIStreamEntity\u003e` を実装したクラスを使用して取得することも可能だと思います．\n\n#### 細かくタイムラインをフェッチする\n\nLink ヘッダに対応しているため，`max_id` や `since_id` に対応している API を使う際は `Links` パラメータの `Next` や `Prev` の ID を使用して連続的に Status などを取得することが出来ます．\n\nTwitter の Pull-to-refresh のように最新のツイートを読み込むような機能などに使われます．\n\n```csharp\n\nvar statuses = await client.GetRecentPublicTimeline(sinceId: 1192);\n// do show some statuses\nstatuses = await client.GetRecentPublicTimeline(sinceId: statuses.Links.Prev.Value);\n// do show next statuses\n\n```\n\n## ライセンス\n\nMIT\n\n## その他\n\nPR は大歓迎です\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamachu%2Fmastodot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyamachu%2Fmastodot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyamachu%2Fmastodot/lists"}