闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

310 lines
9.0 KiB

  1. API overview
  2. ============
  3. ## Contents
  4. - [Available libraries](#available-libraries)
  5. - [Notes](#notes)
  6. - [Methods](#methods)
  7. - Posting a status
  8. - Uploading media
  9. - Retrieving a timeline
  10. - Retrieving notifications
  11. - Following a remote user
  12. - Fetching data
  13. - Deleting a status
  14. - Reblogging a status
  15. - Favouriting a status
  16. - Threads (status context)
  17. - Who reblogged/favourited a status
  18. - Following/unfollowing accounts
  19. - Blocking/unblocking accounts
  20. - Creating OAuth apps
  21. - [Entities](#entities)
  22. - Status
  23. - Account
  24. - [Pagination](#pagination)
  25. ## Available libraries
  26. - [For Ruby](https://github.com/tootsuite/mastodon-api)
  27. - [For Python](https://github.com/halcy/Mastodon.py)
  28. - [For JavaScript](https://github.com/Zatnosk/libodonjs)
  29. - [For JavaScript (Node.js)](https://github.com/jessicahayley/node-mastodon)
  30. ## Notes
  31. When an array parameter is mentioned, the Rails convention of specifying array parameters in query strings is meant. For example, a ruby array like `foo = [1, 2, 3]` can be encoded in the params as `foo[]=1&foo[]=2&foo[]=3`. Square brackets can be indexed but can also be empty.
  32. When a file parameter is mentioned, a form-encoded upload is expected.
  33. ## Methods
  34. ### Posting a new status
  35. **POST /api/v1/statuses**
  36. Form data:
  37. - `status`: The text of the status
  38. - `in_reply_to_id` (optional): local ID of the status you want to reply to
  39. - `media_ids` (optional): array of media IDs to attach to the status (maximum 4)
  40. - `sensitive` (optional): set this to mark the media of the status as NSFW
  41. - `visibility` (optional): either `private`, `unlisted` or `public`
  42. - `spoiler_text` (optional): text to be shown as a warning before the actual content
  43. Returns the new status.
  44. **POST /api/v1/media**
  45. Form data:
  46. - `file`: Image to be uploaded
  47. Returns a media object with an ID that can be attached when creating a status (see above).
  48. ### Retrieving a timeline
  49. **GET /api/v1/timelines/home**
  50. **GET /api/v1/timelines/public**
  51. **GET /api/v1/timelines/tag/:hashtag**
  52. Returns statuses, most recent ones first. Home timeline is statuses from people you follow, mentions timeline is all statuses that mention you. Public timeline is "whole known network", and the last is the hashtag timeline.
  53. Query parameters:
  54. - `max_id` (optional): Skip statuses younger than ID (e.g. navigate backwards in time)
  55. - `since_id` (optional): Skip statuses older than ID (e.g. check for updates)
  56. ### Notifications
  57. **GET /api/v1/notifications**
  58. Returns notifications for the authenticated user. Each notification has an `id`, a `type` (mention, reblog, favourite, follow), an `account` which it came *from*, and in case of mention, reblog and favourite also a `status`.
  59. **GET /api/v1/notifications/:id**
  60. Returns single notification.
  61. **POST /api/v1/notifications/clear**
  62. Clears all of user's notifications.
  63. ### Following a remote user
  64. **POST /api/v1/follows**
  65. Form data:
  66. - uri: username@domain of the person you want to follow
  67. Returns the local representation of the followed account.
  68. ### Fetching data
  69. **GET /api/v1/statuses/:id**
  70. Returns status.
  71. **GET /api/v1/accounts/:id**
  72. Returns account.
  73. **GET /api/v1/accounts/verify_credentials**
  74. Returns authenticated user's account.
  75. **GET /api/v1/accounts/:id/statuses**
  76. Returns statuses by user. Same options as timeline are permitted.
  77. **GET /api/v1/accounts/:id/following**
  78. Returns users the given user is following.
  79. **GET /api/v1/accounts/:id/followers**
  80. Returns users the given user is followed by.
  81. **GET /api/v1/accounts/relationships**
  82. Returns relationships (`following`, `followed_by`, `blocking`) of the current user to a list of given accounts.
  83. Query parameters:
  84. - `id` (can be array): Account IDs
  85. **GET /api/v1/accounts/search**
  86. Returns matching accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database.
  87. Query parameters:
  88. - `q`: what to search for
  89. - `limit`: maximum number of matching accounts to return
  90. **GET /api/v1/blocks**
  91. Returns accounts blocked by authenticated user.
  92. **GET /api/v1/favourites**
  93. Returns statuses favourited by authenticated user.
  94. ### Deleting a status
  95. **DELETE /api/v1/statuses/:id**
  96. Returns an empty object.
  97. ### Reblogging a status
  98. **POST /api/v1/statuses/:id/reblog**
  99. Returns a new status that wraps around the reblogged one.
  100. ### Unreblogging a status
  101. **POST /api/v1/statuses/:id/unreblog**
  102. Returns the status that used to be reblogged.
  103. ### Favouriting a status
  104. **POST /api/v1/statuses/:id/favourite**
  105. Returns the target status.
  106. ### Unfavouriting a status
  107. **POST /api/v1/statuses/:id/unfavourite**
  108. Returns the target status.
  109. ### Threads
  110. **GET /api/v1/statuses/:id/context**
  111. Returns `ancestors` and `descendants` of the status.
  112. ### Who reblogged/favourited a status
  113. **GET /api/v1/statuses/:id/reblogged_by**
  114. **GET /api/v1/statuses/:id/favourited_by**
  115. Returns list of accounts.
  116. ### Following and unfollowing users
  117. **POST /api/v1/accounts/:id/follow**
  118. **POST /api/v1/accounts/:id/unfollow**
  119. Returns the updated relationship to the user.
  120. ### Blocking and unblocking users
  121. **POST /api/v1/accounts/:id/block**
  122. **POST /api/v1/accounts/:id/unblock**
  123. Returns the updated relationship to the user.
  124. ### OAuth apps
  125. **POST /api/v1/apps**
  126. Form data:
  127. - `client_name`: Name of your application
  128. - `redirect_uris`: Where the user should be redirected after authorization (for no redirect, use `urn:ietf:wg:oauth:2.0:oob`)
  129. - `scopes`: This can be a space-separated list of the following items: "read", "write" and "follow" (see [this page](OAuth-details.md) for details on what the scopes do)
  130. - `website`: (optional) URL to the homepage of your app
  131. Creates a new OAuth app. Returns `id`, `client_id` and `client_secret` which can be used with [OAuth authentication in your 3rd party app](Testing-with-cURL.md).
  132. These values should be requested in the app itself from the API for each new app install + mastodon domain combo, and stored in the app for future requests.
  133. **POST /api/v1/devices/register**
  134. Form data:
  135. - `registration_id`: Device token (also called registration token/registration ID)
  136. Apps can use Firebase Cloud Messaging to receive push notifications from the instances, given that the instance admin has acquired a Firebase API key. More in [push notifications](Push-notifications.md). This method requires a user context, i.e. your app will receive notifications for the authorized user.
  137. **POST /api/v1/devices/unregister**
  138. Form data:
  139. - `registration_id`: Device token (also called registration token/registration ID)
  140. To remove the device from receiving push notifications for the user.
  141. ___
  142. ## Entities
  143. ### Status
  144. | Attribute | Description |
  145. |---------------------|-------------|
  146. | `id` ||
  147. | `uri` | fediverse-unique resource ID |
  148. | `url` | URL to the status page (can be remote) |
  149. | `account` | Account |
  150. | `in_reply_to_id` | null or ID of status it replies to |
  151. | `reblog` | null or Status|
  152. | `content` | Body of the status. This will contain HTML (remote HTML already sanitized) |
  153. | `created_at` ||
  154. | `reblogs_count` ||
  155. | `favourites_count` ||
  156. | `reblogged` | Boolean for authenticated user |
  157. | `favourited` | Boolean for authenticated user |
  158. | `sensitive` | Boolean, true if media attachments should be hidden by default |
  159. | `spoiler_text` | If not empty, warning text that should be displayed before the actual content |
  160. | `visibility` | Either `public`, `unlisted` or `private` |
  161. | `media_attachments` | array of MediaAttachments |
  162. | `mentions` | array of Mentions |
  163. | `application` | Application from which the status was posted |
  164. Media Attachment:
  165. | Attribute | Description |
  166. |---------------------|-------------|
  167. | `url` | URL of the original image (can be remote) |
  168. | `preview_url` | URL of the preview image |
  169. | `type` | Image or video |
  170. Mention:
  171. | Attribute | Description |
  172. |---------------------|-------------|
  173. | `url` | URL of user's profile (can be remote) |
  174. | `acct` | Username for local or username@domain for remote users |
  175. | `id` | Account ID |
  176. Application:
  177. | Attribute | Description |
  178. |---------------------|-------------|
  179. | `name` | Name of the app |
  180. | `website` | Homepage URL of the app |
  181. ### Account
  182. | Attribute | Description |
  183. |-------------------|-------------|
  184. | `id` ||
  185. | `username` ||
  186. | `acct` | Equals username for local users, includes @domain for remote ones |
  187. | `display_name` ||
  188. | `note` | Biography of user |
  189. | `url` | URL of the user's profile page (can be remote) |
  190. | `avatar` | URL to the avatar image |
  191. | `header` | URL to the header image |
  192. | `locked` | Boolean for when the account cannot be followed without waiting for approval first |
  193. | `followers_count` ||
  194. | `following_count` ||
  195. | `statuses_count` ||
  196. ## Pagination
  197. API methods that return collections of items can return a `Link` header containing URLs for the `next` and `prev` pages. [Link header RFC](https://tools.ietf.org/html/rfc5988)