LoginSignup
31
29

More than 5 years have passed since last update.

MastodonのAPIをcurlで叩いてみるサンプル

Last updated at Posted at 2017-04-13

Mastodon

s_mastodon.jpg

Mastodon
https://github.com/tootsuite/mastodon
twitter likeなオープンソースのSNS。
誰でもインスタンスを立てることが出来て、インスタンス内のTOOT(twitterでいうtweet)が流れてくるLocal Timelineと、他のインスタンスのTOOTも流れてくるFederated Timelineというのもあります。

MastodonのAPIをcurlで叩いてみる

とりあえずどこかのインスタンスに登録したら、アプリケーションを登録してclient_idとclient_secretを手に入れます
(インスタンスによってurlは変更する)
(scopesは使う内容に沿って設定する)

$ curl -X POST 'https://mastodon.social/api/v1/apps' --data 'client_name=YourApp&redirect_uris=urn:ietf:wg:oauth:2.0:oob&scopes=read'

次に、今手に入れたclient_idとclient_secretを使ってaccess_tokenを手に入れます
(client_idとclient_secretは今後も使うので保存しておく)

$ curl -X POST -d "client_id=CLIENT_ID_HERE&client_secret=CLIENT_SECRET_HERE&grant_type=password&username=YOUR_EMAIL&password=YOUR_PASSWORD" -Ss https://mastodon.social/oauth/token

headerにaccess_tokenをセットすればok

$ curl --header "Authorization: Bearer ACCESS_TOKEN_HERE" -sS https://mastodon.social/api/v1/timelines/home

詳しいことはdocumentを参照。
https://github.com/tootsuite/documentation/tree/master/Using-the-API

おわりに

Mastodon今のところ(2017/4/13現在)、twitter黎明期のような感じがして非常に面白いですが、
インスタンスの運営を個人でやってる方が多いので、その辺りはきちんと理解して支援できるところは支援しながら使っていきたいと思います。

追記: scopesに関する記述を追記しました

31
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
29