Dabbling with the Mastodon API

I’ve been meaning to get all the stuff that used to be automated to Twitter to work with Mastodon.

I took about 15 minutes1 after reading a Mastodon-related post from Alan to mess around and see what I could figure out. Now I’ve got 15 minutes to write it down. Consider that half an hour devoted to better mental health.

I’m mainly just looking around at this point and seeing what data I can get in what ways. It’s public data and documented here.

I can get the most recent public posts with this endpoint/URL. https://social.ds106.us/api/v1/timelines/public

You can add ?limit=22 or something similar to change how many you get back. 20 is the default. It’s not clear to me what the upper limit is. You can append ?page=3 to move through the list of returns.

To get a particular account’s posts, you need their ID. That URL is https://social.ds106.us/api/v1/accounts/lookup?acct=twwoodward for the twwoodward account.

With that ID, I can get the updates from that account https://social.ds106.us/api/v1/accounts/109750793793068583/statuses/

I can also get updates by tag with https://social.ds106.us/api/v1/timelines/tag/tdc4417?limit=40

I could take that URL and make a little display widget for a hashtag. Twitter will charge you $1000 bucks for something like that these days.

See the Pen
Mastodon tweets by tag
by Tom (@twwoodward)
on CodePen.

Next up will be getting the old blog posts publishing to Mastodon. Probably going to do that via PHP but I might also revisit my old Google Sheet javascript contraption I built to post to Twitter.

1 It is Friday after all.

Leave a Reply