GNU social

提供:GNU social JP Wiki
2024年1月6日 (土) 11:48時点におけるGnusocialjp (トーク | 投稿記録)による版 (Get)

API

GNU socialのWeb APIについては,フッターの [Help](doc/help), [About](doc/about), [TOS](doc/tos) などを選択して遷移できるDOCS画面の [API](doc/api) (Api - GNU social JP) を選択することで表示できる。

ソースコード上はdoc-src (v2.0.2 - NotABug.org: Free code hosting) 配下にAPI文書が格納されている。

AtomPubとTwitter互換APIの2種類のAPIを利用可能。Twitter APIのほうがシンプルだが、AtomPubだとリッチテキストが使用可能など、機能に若干の違いがある。

以下の記事も参考になる。

API末尾の拡張子atom/xml/jsonに応じた形式の応答をサーバーが返す模様。

Twitter API

GNU socialのTwitter APIは完全互換ではないので注意が必要。

Post

wget -O - \
    --http-user=vaginaplant \
    --http-passwd=XXXXXX \
    --post-data='status=LGBTPZN' \
    https://freezepeach.xyz/api/statuses/update.json
curl -u username:password -d "status=status" https://domain/api/statuses/update.json

添付ファイルの例。

curl -u username:password \
  -F "media=@image.jpg" \
  -F "status=post message" \
  https://domain.jp/api/statuses/update.json

Get

JSONの配列で応答が返ってくる。

 curl $HOST/api/statuses/user_timeline/test.json
 [
   {
     "text": "QSettings",
     "truncated": false,
     "created_at": "Thu Jan 04 11:51:11 +0900 2024",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2024-01-04:noticeId=5026657:objectType=note",
     "source": "",
     "source_link": null,
     "id": 5026657,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "QSettings",
     "statusnet_conversation_id": 2539347,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/5026657",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": true,
     "is_local": true,
     "favorited": false,
     "repeated": false
   },
   {
     "text": "test 2",
     "truncated": false,
     "created_at": "Thu Jan 04 10:41:35 +0900 2024",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2024-01-04:noticeId=5026119:objectType=note",
     "source": "",
     "source_link": null,
     "id": 5026119,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "test 2",
     "statusnet_conversation_id": 2539084,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/5026119",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": true,
     "is_local": true,
     "favorited": false,
     "repeated": false
   },
   {
     "text": "test (https://gnusocial.jp/test) started following めうるみ (とけた) (https://mewl.me/@mewl).",
     "truncated": false,
     "created_at": "Thu Sep 08 08:32:22 +0900 2022",
     "in_reply_to_status_id": null,
     "uri": "tag:gnusocial.jp,2022-09-07:subscription:2:person:9308:2022-09-08T08:32:22+09:00",
     "source": "activity",
     "source_link": null,
     "id": 274143,
     "in_reply_to_user_id": null,
     "in_reply_to_screen_name": null,
     "geo": null,
     "user": {
       "id": 2,
       "name": "test",
       "screen_name": "test",
       "location": "Japan",
       "description": "gnusocial.jpのテストアカウントです。\r\nID/PW=test/666666。\r\n投稿にはメール登録が必要です。基本は閲覧用です。",
       "profile_image_url": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_https": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-stream.png",
       "profile_image_url_profile_size": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "profile_image_url_original": "https://gnusocial.jp/theme/gnusocialjp/default-avatar-profile.png",
       "groups_count": 1,
       "linkcolor": false,
       "backgroundcolor": false,
       "url": "https://example.com",
       "protected": false,
       "followers_count": 15,
       "friends_count": 1,
       "created_at": "Mon Jul 18 13:10:39 +0900 2022",
       "utc_offset": "32400",
       "time_zone": "Asia/Tokyo",
       "statuses_count": 35,
       "following": false,
       "statusnet_blocking": false,
       "notifications": false,
       "statusnet_profile_url": "https://gnusocial.jp/test",
       "cover_photo": false,
       "background_image": false,
       "profile_link_color": false,
       "profile_background_color": false,
       "profile_banner_url": false,
       "is_local": true,
       "is_silenced": false,
       "rights": {
         "delete_user": false,
         "delete_others_notice": false,
         "silence": false,
         "sandbox": false
       },
       "is_sandboxed": false,
       "ostatus_uri": "https://gnusocial.jp/index.php/user/2",
       "favourites_count": 0
     },
     "statusnet_html": "test started following めうるみ (とけた).",
     "statusnet_conversation_id": 154562,
     "statusnet_in_groups": false,
     "external_url": "https://gnusocial.jp/notice/274143",
     "in_reply_to_profileurl": null,
     "in_reply_to_ostatus_uri": null,
     "attentions": [],
     "fave_num": 0,
     "repeat_num": 0,
     "is_post_verb": false,
     "is_local": true,
     "favorited": false,
     "repeated": false
   }
 ]