あっさりできた。

準備

  1. マストドンの任意インスタンスでアカウントを作成する(mstdn.jppawoo.net等)
  2. アクセストークンを作成する
    1. 各インスタンスの設定で開発新規アプリをクリックする mstdn.jp, pawoo.net
    2. アプリの名前, アプリのウェブサイト, アクセス権を適当にセットして送信する
    3. 出現したアクセストークンをどこかにメモっておく(他人に知られないように)

ターミナルで叩く

Linuxコマンドcurlを使ってマストドンAPIの実行に必要なHTTP POSTを実行してみた。

curl -X POST \
    -d 'status=Hello%20Qiitadon%21' \
    -d 'visibility=unlisted' \
    --header 'Authorization: Bearer xxxxx...xxxxx' \
    -sS https://qiitadon.com/api/v1/statuses
DOMAIN=pawoo.net
TOKEN=アクセストークンをここに書く
status="マストドンAPIのテストです"
curl -X POST \
    -H "Authorization: Bearer $TOKEN" \
	-F "status=$status" \
	https://$DOMAIN/api/v1/statuses

あっさりできた。

応答は以下のとおり。

{"id":"108399819381378567","created_at":"2022-06-01T02:19:38.375Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"ja","uri":"https://pawoo.net/users/ytyaru_webmention/statuses/108399819381378567","url":"https://pawoo.net/@ytyaru_webmention/108399819381378567","replies_count":0,"reblogs_count":0,"favourites_count":0,"pixiv_cards":[],"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003eマストドンAPIのテストです\u003c/p\u003e","reblog":null,"application":{"name":"マストドンAPIテスト用アプリ","website":"https://ytyaru.github.io/"},"account":{"id":"1724184","username":"ytyaru_webmention","acct":"ytyaru_webmention","display_name":"","locked":false,"bot":false,"discoverable":null,"group":false,"created_at":"2022-05-29T00:08:36.932Z","note":"\u003cp\u003e\u003c/p\u003e","url":"https://pawoo.net/@ytyaru_webmention","avatar":"https://pawoo.net/avatars/original/missing.png","avatar_static":"https://pawoo.net/avatars/original/missing.png","header":"https://pawoo.net/headers/original/missing.png","header_static":"https://pawoo.net/headers/original/missing.png","followers_count":0,"following_count":2,"statuses_count":7,"last_status_at":"2022-06-01","emojis":[],"oauth_authentications":[],"fields":[]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}

JSONきれい ~JSON整形ツール~で整形したのが以下。Unicodeデコードもされている。

{
	"id": "108399819381378567",
	"created_at": "2022-06-01T02:19:38.375Z",
	"in_reply_to_id": null,
	"in_reply_to_account_id": null,
	"sensitive": false,
	"spoiler_text": "",
	"visibility": "public",
	"language": "ja",
	"uri": "https://pawoo.net/users/ytyaru_webmention/statuses/108399819381378567",
	"url": "https://pawoo.net/@ytyaru_webmention/108399819381378567",
	"replies_count": 0,
	"reblogs_count": 0,
	"favourites_count": 0,
	"pixiv_cards": [],
	"favourited": false,
	"reblogged": false,
	"muted": false,
	"bookmarked": false,
	"pinned": false,
	"content": "<p>マストドンAPIのテストです</p>",
	"reblog": null,
	"application": {
		"name": "マストドンAPIテスト用アプリ",
		"website": "https://ytyaru.github.io/"
	},
	"account": {
		"id": "1724184",
		"username": "ytyaru_webmention",
		"acct": "ytyaru_webmention",
		"display_name": "",
		"locked": false,
		"bot": false,
		"discoverable": null,
		"group": false,
		"created_at": "2022-05-29T00:08:36.932Z",
		"note": "<p></p>",
		"url": "https://pawoo.net/@ytyaru_webmention",
		"avatar": "https://pawoo.net/avatars/original/missing.png",
		"avatar_static": "https://pawoo.net/avatars/original/missing.png",
		"header": "https://pawoo.net/headers/original/missing.png",
		"header_static": "https://pawoo.net/headers/original/missing.png",
		"followers_count": 0,
		"following_count": 2,
		"statuses_count": 7,
		"last_status_at": "2022-06-01",
		"emojis": [],
		"oauth_authentications": [],
		"fields": []
	},
	"media_attachments": [],
	"mentions": [],
	"tags": [],
	"emojis": [],
	"card": null,
	"poll": null
}

次はこれをJavaScriptで叩きたい。