jointrashposs/content/tw/docs/4.for-developers/api/token.md
かっこかり d7ad8387a9
New Crowdin updates (#92)
* New translations 1.about-misskey.md (French)

* New translations 2.get-started.md (French)

* New translations 3.join-server.md (French)

* New translations 4.things-to-know.md (French)

* New translations ads.md (French)

* New translations drive.md (French)

* New translations mfm.md (French)

* New translations mute-and-block.md (French)

* New translations pages.md (French)

* New translations poll.md (French)

* New translations thread-mute.md (French)

* New translations webhook.md (French)

* New translations 1.troubleshooting.md (French)

* New translations donate.md (French)

* New translations misskey-hub.md (French)

* New translations announcement.md (French)

* New translations role.md (French)

* New translations 1.index.md (French)

* New translations bash.md (French)

* New translations docker.md (French)

* New translations kubernetes.md (French)

* New translations manual.md (French)

* New translations ubuntu-manual.md (French)

* New translations cdn.md (French)

* New translations disable-timelines.md (French)

* New translations 1.index.md (French)

* New translations permission.md (French)

* New translations 1.index.md (French)

* New translations token.md (French)

* New translations 5.releases.md (French)

* New translations 1.about-misskey.md (Italian)

* New translations 2.get-started.md (Italian)

* New translations 3.join-server.md (Italian)

* New translations 4.things-to-know.md (Italian)

* New translations ads.md (Italian)

* New translations drive.md (Italian)

* New translations mfm.md (Italian)

* New translations mute-and-block.md (Italian)

* New translations pages.md (Italian)

* New translations poll.md (Italian)

* New translations share-form.md (Italian)

* New translations thread-mute.md (Italian)

* New translations webhook.md (Italian)

* New translations 1.troubleshooting.md (Italian)

* New translations donate.md (Italian)

* New translations misskey-hub.md (Italian)

* New translations announcement.md (Italian)

* New translations role.md (Italian)

* New translations 1.index.md (Italian)

* New translations bash.md (Italian)

* New translations docker.md (Italian)

* New translations kubernetes.md (Italian)

* New translations manual.md (Italian)

* New translations ubuntu-manual.md (Italian)

* New translations cdn.md (Italian)

* New translations disable-timelines.md (Italian)

* New translations 1.index.md (Italian)

* New translations permission.md (Italian)

* New translations 1.index.md (Italian)

* New translations token.md (Italian)

* New translations 5.releases.md (Italian)

* New translations 1.about-misskey.md (Korean)

* New translations 1.warning.md (Korean)

* New translations 2.get-started.md (Korean)

* New translations 3.join-server.md (Korean)

* New translations 4.things-to-know.md (Korean)

* New translations ads.md (Korean)

* New translations drive.md (Korean)

* New translations mfm.md (Korean)

* New translations mute-and-block.md (Korean)

* New translations pages.md (Korean)

* New translations poll.md (Korean)

* New translations share-form.md (Korean)

* New translations thread-mute.md (Korean)

* New translations webhook.md (Korean)

* New translations 1.troubleshooting.md (Korean)

* New translations donate.md (Korean)

* New translations misskey-hub.md (Korean)

* New translations announcement.md (Korean)

* New translations role.md (Korean)

* New translations 1.index.md (Korean)

* New translations bash.md (Korean)

* New translations docker.md (Korean)

* New translations kubernetes.md (Korean)

* New translations manual.md (Korean)

* New translations ubuntu-manual.md (Korean)

* New translations cdn.md (Korean)

* New translations disable-timelines.md (Korean)

* New translations 1.index.md (Korean)

* New translations permission.md (Korean)

* New translations 1.index.md (Korean)

* New translations token.md (Korean)

* New translations 5.releases.md (Korean)

* New translations 1.about-misskey.md (Polish)

* New translations 2.get-started.md (Polish)

* New translations 3.join-server.md (Polish)

* New translations 4.things-to-know.md (Polish)

* New translations ads.md (Polish)

* New translations drive.md (Polish)

* New translations mfm.md (Polish)

* New translations mute-and-block.md (Polish)

* New translations pages.md (Polish)

* New translations poll.md (Polish)

* New translations share-form.md (Polish)

* New translations thread-mute.md (Polish)

* New translations webhook.md (Polish)

* New translations 1.troubleshooting.md (Polish)

* New translations donate.md (Polish)

* New translations misskey-hub.md (Polish)

* New translations announcement.md (Polish)

* New translations role.md (Polish)

* New translations 1.index.md (Polish)

* New translations bash.md (Polish)

* New translations docker.md (Polish)

* New translations kubernetes.md (Polish)

* New translations manual.md (Polish)

* New translations ubuntu-manual.md (Polish)

* New translations cdn.md (Polish)

* New translations disable-timelines.md (Polish)

* New translations 1.index.md (Polish)

* New translations permission.md (Polish)

* New translations 1.index.md (Polish)

* New translations token.md (Polish)

* New translations 5.releases.md (Polish)

* New translations ja-jp.yml (Chinese Simplified)

* New translations 1.about-misskey.md (Chinese Simplified)

* New translations 2.get-started.md (Chinese Simplified)

* New translations 3.join-server.md (Chinese Simplified)

* New translations 4.things-to-know.md (Chinese Simplified)

* New translations ads.md (Chinese Simplified)

* New translations drive.md (Chinese Simplified)

* New translations mfm.md (Chinese Simplified)

* New translations mute-and-block.md (Chinese Simplified)

* New translations pages.md (Chinese Simplified)

* New translations poll.md (Chinese Simplified)

* New translations share-form.md (Chinese Simplified)

* New translations thread-mute.md (Chinese Simplified)

* New translations webhook.md (Chinese Simplified)

* New translations 1.troubleshooting.md (Chinese Simplified)

* New translations donate.md (Chinese Simplified)

* New translations misskey-hub.md (Chinese Simplified)

* New translations announcement.md (Chinese Simplified)

* New translations role.md (Chinese Simplified)

* New translations 1.index.md (Chinese Simplified)

* New translations bash.md (Chinese Simplified)

* New translations docker.md (Chinese Simplified)

* New translations kubernetes.md (Chinese Simplified)

* New translations manual.md (Chinese Simplified)

* New translations ubuntu-manual.md (Chinese Simplified)

* New translations cdn.md (Chinese Simplified)

* New translations disable-timelines.md (Chinese Simplified)

* New translations 1.index.md (Chinese Simplified)

* New translations permission.md (Chinese Simplified)

* New translations 1.index.md (Chinese Simplified)

* New translations token.md (Chinese Simplified)

* New translations 5.releases.md (Chinese Simplified)

* New translations 1.about-misskey.md (Chinese Traditional)

* New translations 2.get-started.md (Chinese Traditional)

* New translations 3.join-server.md (Chinese Traditional)

* New translations 4.things-to-know.md (Chinese Traditional)

* New translations ads.md (Chinese Traditional)

* New translations drive.md (Chinese Traditional)

* New translations mfm.md (Chinese Traditional)

* New translations mute-and-block.md (Chinese Traditional)

* New translations pages.md (Chinese Traditional)

* New translations poll.md (Chinese Traditional)

* New translations share-form.md (Chinese Traditional)

* New translations thread-mute.md (Chinese Traditional)

* New translations webhook.md (Chinese Traditional)

* New translations 1.troubleshooting.md (Chinese Traditional)

* New translations donate.md (Chinese Traditional)

* New translations misskey-hub.md (Chinese Traditional)

* New translations announcement.md (Chinese Traditional)

* New translations role.md (Chinese Traditional)

* New translations 1.index.md (Chinese Traditional)

* New translations bash.md (Chinese Traditional)

* New translations docker.md (Chinese Traditional)

* New translations kubernetes.md (Chinese Traditional)

* New translations manual.md (Chinese Traditional)

* New translations ubuntu-manual.md (Chinese Traditional)

* New translations cdn.md (Chinese Traditional)

* New translations disable-timelines.md (Chinese Traditional)

* New translations 1.index.md (Chinese Traditional)

* New translations permission.md (Chinese Traditional)

* New translations 1.index.md (Chinese Traditional)

* New translations token.md (Chinese Traditional)

* New translations publish-on-your-website.md (Chinese Traditional)

* New translations 5.releases.md (Chinese Traditional)

* New translations 1.about-misskey.md (English)

* New translations 2.get-started.md (English)

* New translations 3.join-server.md (English)

* New translations 4.things-to-know.md (English)

* New translations ads.md (English)

* New translations drive.md (English)

* New translations mfm.md (English)

* New translations mute-and-block.md (English)

* New translations pages.md (English)

* New translations poll.md (English)

* New translations share-form.md (English)

* New translations thread-mute.md (English)

* New translations webhook.md (English)

* New translations 1.troubleshooting.md (English)

* New translations donate.md (English)

* New translations misskey-hub.md (English)

* New translations announcement.md (English)

* New translations role.md (English)

* New translations 1.index.md (English)

* New translations bash.md (English)

* New translations docker.md (English)

* New translations kubernetes.md (English)

* New translations manual.md (English)

* New translations ubuntu-manual.md (English)

* New translations cdn.md (English)

* New translations disable-timelines.md (English)

* New translations 1.index.md (English)

* New translations permission.md (English)

* New translations 1.index.md (English)

* New translations token.md (English)

* New translations 5.releases.md (English)

* New translations 1.about-misskey.md (Indonesian)

* New translations 2.get-started.md (Indonesian)

* New translations 3.join-server.md (Indonesian)

* New translations 4.things-to-know.md (Indonesian)

* New translations ads.md (Indonesian)

* New translations drive.md (Indonesian)

* New translations mfm.md (Indonesian)

* New translations mute-and-block.md (Indonesian)

* New translations pages.md (Indonesian)

* New translations poll.md (Indonesian)

* New translations share-form.md (Indonesian)

* New translations thread-mute.md (Indonesian)

* New translations webhook.md (Indonesian)

* New translations 1.troubleshooting.md (Indonesian)

* New translations donate.md (Indonesian)

* New translations misskey-hub.md (Indonesian)

* New translations announcement.md (Indonesian)

* New translations role.md (Indonesian)

* New translations 1.index.md (Indonesian)

* New translations bash.md (Indonesian)

* New translations docker.md (Indonesian)

* New translations kubernetes.md (Indonesian)

* New translations manual.md (Indonesian)

* New translations ubuntu-manual.md (Indonesian)

* New translations cdn.md (Indonesian)

* New translations disable-timelines.md (Indonesian)

* New translations 1.index.md (Indonesian)

* New translations permission.md (Indonesian)

* New translations 1.index.md (Indonesian)

* New translations token.md (Indonesian)

* New translations 5.releases.md (Indonesian)
2023-12-29 13:23:03 +09:00

5.5 KiB
Raw Blame History

取得存取權杖

要開始使用 API您需要取得與將使用API的帳戶相關聯的存取權杖。 本文件將介紹取得存取權杖的步驟,然後說明如何使用基本 API。

基本上API需要存取權杖進行請求。 存取權杖是與用戶關聯的身份驗證資料用於識別使用API的用戶同時管理每個存取權杖具有什麼樣的操作權限。

:::tip

你可以輕鬆地獲得自己的存取權杖,也可以獲取使用你的應用程序的不特定用戶的存取權杖。

:::

あなた自分自身のアクセストークンは簡単に取得できるほか、あなたのアプリケーションを使用することになる不特定のユーザーのアクセストークンを取得することもできます。

  • 前者の場合: 「自分自身のアクセストークンを手動発行する」 に進む
  • 後者の場合: 「アプリケーション利用者にアクセストークンの発行をリクエストする」 に進む

自分自身のアクセストークンを手動発行する

Misskey Webの「設定 > API」で、自分のアクセストークンを発行できます。

:::danger

アクセストークンは他人に知られないようにしてください。

:::

アプリケーション利用者にアクセストークンの発行をリクエストする

アプリケーションを利用するユーザー(以下単に「ユーザー」と呼びます)のアクセストークンを取得するには、以下の手順で発行をリクエストします。

:::tip

以下に説明する方法は、アプリを作成せずインスタントにアクセストークンを発行する、MiAuthと呼ばれるものです。

アプリ作成方式でのアクセストークン取得方法もあります(旧来型)。 :::

Step 1

UUIDを生成する。以後これをセッションIDと呼びます。

:::danger

このセッションIDは毎回生成し、使いまわさないようにしてください。

:::

Step 2

アプリケーション認証フォームをユーザーのブラウザで表示させる。認証フォームは、以下の形式のURLで開くことができます:

https://misskey.io/miauth/c1f6d42b-468b-4fd2-8274-e58abdedef6f?name=MyApp&callback=https%3A%2F%2Fmyapp.example.com%2Fcallback&permission=write:notes,write:following,read:drive

ここで、

  • {host}の部分は、ユーザーのサーバーのホストに置き換えます。通常ホストはユーザーが入力します。
  • {session}の部分は、セッションIDに置き換えます。

使用者授予應用程式存取權限後,向下列格式的網址傳送 POST 請求,將傳回一個包含存取權杖的 JSON 作為回應。

名前 説明
name アプリケーション名。
icon アプリケーションのアイコン画像URL。
callback 認証が終わった後にリダイレクトするURL。
リダイレクト時には、sessionというクエリパラメータでセッションIDが付きます。
permission アプリケーションが要求する権限。
要求する権限を,で区切って列挙します。権限の一覧はこちらで確認できます。

:::tip{label='例'}

https://misskey.io/miauth/c1f6d42b-468b-4fd2-8274-e58abdedef6f?name=MyApp&callback=https%3A%2F%2Fmyapp.example.com%2Fcallback&permission=write:notes,write:following,read:drive

:::

Step 3

ユーザーがアプリケーションアクセスを許可した後、次の形式のURLにPOSTリクエストすると、レスポンスとしてアクセストークンを含むJSONが返ります。

https://{host}/api/miauth/{session}/check

ここで、

  • 所有 HTTP API 均為 POST請求和回應均為 JSON 格式drive/files/create 除外)。
  • 在請求標頭中指定 Content-Type: application/json

レスポンスに含まれるプロパティは以下の通りです:

名前 説明
token ユーザーのアクセストークン。
user ユーザーの情報。

APIの利用

アクセストークンが取得できたら、各種エンドポイントにリクエストすることでAPIの利用が行えます。

:::tip

  • HTTP APIはすべてPOSTで、リクエスト/レスポンスともにJSON形式ですdrive/files/createを除く
  • 要求ヘッダーにContent-Type: application/jsonを指定します。
  • アクセストークンは、iというパラメータ名でリクエストボディJSONに含めます。
  • ベースURLはhttps://{サーバーのドメイン}/apiです。

:::

アクセストークン付きのボディの例metaの場合:

{
    "i": "HogEFugA1341",
    "detail": false
}

APIの詳細は、APIリファレンスを参照してください。

:::warning

MisskeyはRESTを採用していません。

:::

また、MisskeyはHTTP APIだけでなく、ストリーミングAPIも提供しています。ストリーミングAPIの詳細はこちらのドキュメントを参照してください。