Decentralized social media
Welcome to the Fediverse
If you're looking for social media options where the user has more control, you'll find a range of options to explore in the Fediverse, including the popular Mastodon.
Despite what it may seem, despite its promise of unbridled communication possibilities and its supposed gift of giving voice to the traditionally voiceless, current social media is a walled garden at best, although a slimy cesspit with bars over the top would be a more apt description.
The problem with the current social media status quo is that the platform does not have your interests at heart. The companies that run proprietary social media platforms gradually introduce more and more restrictive terms of service, package your personal data and sell it off to other companies and governments, make their algorithms more manipulative, and so on.
In the Beginning
You could renounce social media altogether and go and live as hermit, but why throw the baby out with the bath water? The Fediverse [1] is the FOSS community's response to walled-gardened, personal data-leaching, closed, and proprietary social media. Strictly speaking, the Fediverse would cover all social media services (and some services that are not related to social media at all) that do not rely on a centralized and controlling entity (like, say, Facebook, Twitter, or Google), but instead allow a user to run their own server (often called a "pod") and to connect it to a network of similar servers to share the media between them. This allows user A to post to pod X and user B to read it from pod Y.
The genesis of the Fediverse can be traced back to projects like diaspora* [2] or Identi.ca [3], the earlier attempts to create a non-centralized network of social media. Things evolved and, Identi.ca's creator, Evan Prodromou, developed pump.io [4], a framework upon which developers can build social media services.
It then came to pass that the W3C saw that pump.io was good. It took its essence and breathed new life into it, transforming it into ActivityPub [5] and publishing a recommendation.
The modern Fediverse was born. Let there be posts!
ActivityPub is a protocol and an API that allows the services that follow it to communicate across the Fediverse with nodes of the same kind of service or even with nodes of different services. For example, you can post a picture to your account on Pixelfed [6], a photo-sharing service (Figure 1), and have it pop up on the feeds of people who follow you on Mastodon [7], the Fediverse's most popular microblogging service (Figure 2).
The Fediverse not only shares posts, but it also shares resources among nodes and even, by using P2P technologies, among clients. Say you decide to open your own PeerTube pod on your own server. Sure, you will need a decent amount of bandwidth, but not as much as you think, as the video service has clients watching the same clip share the load.
Apart from Mastodon, PeerTube, and Pixelfed, there is a Fediverse social media platform for audio aimed at musicians and podcasters called Funkwhale [8], and then there is Hubzilla [9], which describes itself as "a powerful platform for creating interconnected websites featuring a decentralized identity, communications, and permissions framework built using common web server technology" – so a federated Facebook? Hubzilla is a bit rough around the edges, and I haven't totally figured it out yet.
To be fair, most of the Fediverse is still rough around the edges. Pixelfed lacks a mobile phone app with camera integration, which, if I understand things right, would make it more attractive to Instagrammers. There does not seem to be a way of seeing who your subscribers are on PeerTube, and Hubzilla's interface looks dated and only implements ActivityPub as a plugin, so I'm guessing that connectivity with other services throughout its network may be spotty.
But this is kind of normal: Many of the Fediverse's services are in a nascent phase, with few users and nearly no posts.
This is not the case of Mastodon.
Mastodon Basics
Mastodon has been the subject of many articles predicting its demise, a nearly certain sign it will survive. Indeed, according to Mastodon's account-counting bot, Mastodon is quickly approaching 3.5 million users and is arguably the most popular, non-proprietary social media platform out there.
One of the reasons for its popularity may be due to its design – Mastodon just looks good (Figure 2 again). It is also simple to set up and use.
Mastodon is laid out in columns. The first column from the left is where you write your toots (up to 512 characters long). You can also add attachments: up to four pictures, or a video, or an audio file. You can also create a poll, decide on the privacy of the post (public, for followers only, direct message, etc.) and set the content as hidden behind a warning, which is ideal for spoilers or for potentially offensive material.
The second column shows your feed. This contains your own toots and those of the people you follow. The third column shows notifications, that is, when people favorite or boost your toots, direct messages they send you, comments, and so on.
The fourth column is a bit of a wildcard. By default, it shows a menu that allows you to pick between showing the local timeline (i.e., all the toots sent in your pod as they happen), the federated timeline, or all the toots posted in your pods network as they happen. You can also turn it into an inbox and show direct messages here, list the toots you have favorited over time, and make lists in which to classify the accounts you follow. Or if you click on a user's profile, it shows the user's information. Their latest stats and toots will also show up here.
You can also change what is shown in the fourth column using the toolbar across the top of the first column. The Getting Started button will take you back to the fourth column's original menu, the Local Timeline and Federated Timeline buttons will show each of those timelines in the fourth column.
The Settings button lets you configure everything regarding your account, from your display name and the look and feel of you account, to the custom applications you can use to mine information from Mastodon (more about this later).
In the Settings, by the way, you can also switch on a feature that lets you add more columns to your Mastodon interface. Go to Settings | Preferences and check the Enable Advanced Web Interface checkbox. The description says:
"If you want to make use of your entire screen width, the advanced web interface allows you to configure many different columns to see as much information at the same time as you want: Home, notifications, federated timeline, any number of lists, and hashtags."
Annoyingly, it does not say how to do this, so here it is: Say you want to add a new column with the federated timeline. Go to the fourth column, click on Federated Timeline, and the federated timeline will appear, occluding the Getting Started panel/menu/column/thingy. At the top right of the timeline, there is a configuration button. It looks like three little sliders. Click it and then click on + Pin in the fold out that appears. The column is now fixed and the Getting Started panel/menu/column/thingy will pop up to the right, allowing you to create more columns.
If you are interested in a trending topic, click on its hashtag and a feed with all the toots containing that hashtag will appear over the Getting Started column. Again, by clicking the configuration button in the top right of the column, you can pin the column and follow the topic as it develops (Figure 3).
You can search for hashtags (and users and more things) using the search box located in the first column on the left, right beneath the toolbar.
Coding for Mastodon
With the rise of Mastodon's popularity, a few clients have popped up that allow you to access you account from your mobile. My personal preference leans towards Fedilab [10], which lets you manage accounts from Mastodon, PeerTube and soon Pixelfed, all from one single app (Figure 4).
If you can't find a client you like, don't despair: Coding for Mastodon is easy. Its API is well-documented, and there are plenty of hooks in several programming languages.
Let's use Python to do some simple reading of data from accounts.
The module you need is called Mastodon.py
[11], and the documentation is located at [12].
You can install the modules with
sudo pip install Mastodon.py
Let's write a short script that will solve a real problem: Mastodon's web stops showing the precise number of followers from 1,000 followers up, opting for showing, for example 2.7K, instead of, say, 2,734, 2,755, or whatever. This makes tracking the popularity of an account difficult.
Your first app uses the identification number of a toot to print out the name of the account and the number of its followers.
Before you even start to write your code, you must give your app a name and register it with the federated network of Mastodon pods you are going to query. To do this, log into your Mastodon account. Go to Settings | Development and click the New Application button. Fill in the Application Name text box and choose the scope of your application. In this case, you only have to leave the Read checkbox marked, because that is all you are going to do: Read data from the network.
Click Submit at the bottom of the page, and this will log your application with the federated network.
Now, if you click on your application's name, at the top of the page it will show a list of three keys. The key labeled Client Secret is the one you need to finish registering your application with the network (Figure 5).
To finalize the registration, create your application with the code shown in Listing 1.
Listing 1
accountfollowers.py (Part One)
01 from mastodon import Mastodon 02 03 Mastodon.create_app( 04 'accountfollowers', 05 api_base_url = '[URL OF MASTODON INSTANCE]', 06 to_file = '[CLIENT SECRET]' 07 )
On line 5, you put the URL of the Mastodon instance where you are registering your application. It will look something like:
api_base_url = 'https://mastodon.xyz/'
On line 6 you put the secret client key you saw above. The line will end up looking like this:
to_file = 'HHssuwd_AhTot4LlyMaDEUpK3y_aEJHjjIWJj2289usQsjSJqiw-d'
You run this version of your app once and then you can comment out or delete the registration code.
The final version of your application reads a list of toot URLs (see the box "Grabbing a Toot") from the command line and then processes them to figure out the account from whence they came and the number of followers that account has. The application would look like what you can see in Listing 2.
Grabbing a Toot
To grab the URL of an individual toot, click on the time the toot was published. This is in the upper right-hand corner of the toots box. The toot opens in a new window/tab with a URL that will look something like:
https://framapiaf.org/@davidrevoy/ 102552017830926864
Breaking it down, framapiaf.org is the Mastodon instance (pod) hosting the toot, @davidrevoy is the user, and 102552017830926864 is the unique ID assigned to the toot.
Listing 2
accountfollowers.py (Part Two)
01 import sys 02 from mastodon import Mastodon 03 04 sys.argv.pop(0) 05 for eachToot in sys.argv: 06 tinstance = eachToot.split("/")[2] 07 taccount = eachToot.split("/")[3] 08 tid = eachToot.split("/")[4] 09 10 mastodon = Mastodon ( 11 client_id = '[CLIENT SECRET]', 12 api_base_url = 'https://' + tinstance 13 ) 14 15 print ("User:" + taccount) 16 print ("ID: " + str(mastodon.status(tid)['account']['id'])) 17 print ("Followers: " + str(mastodon.status(tid)['account']['followers_count'])) 18 print ("===")
This works is as follows:
- On lines 1 and 2, you import your modules:
sys
to be able to read parameters off of the command line, andmastodon
for all the Mastodon stuff. - On line 4, you remove the first element from the list of parameters passed from the command line, as it is the name of the script, and all you want are the links.
- On line 5, you loop through the links.
On lines 6 through 8, you split the URL for each toot up into the Mastodon pod (instance) it was posted to, the name of the account, and the ID of the toot itself. If you have a URL for toot that looks like this:
https://mastodon.technology/@kde/102455343978152552
tinstance
will contain mastodon.technology, taccount
will contain @kde and tid
will contain 102455343978152552.
- On lines 10 through 13, you create a
mastodon
object that will let your application connect to the instance and identify itself with the secret client code. - On line 15, you print the user name to the console.
- On line 16 and 17, you use
Mastodon.py
'sstatus()
function to read data from the Mastodon instance.
The status()
[13] function reads a toot (known in ActivityPub jargon as a status) given an id for the toot. It returns a toot
dictionary [14], containing everything you need to know about the toot. The toot
dictionary includes a subdictionary called account
[15], which contains information about the account the toot came from, including the accounts id
number (accessed in line 16) and the follower_count
(accessed in line 17).
You can call your script like this:
python accountfollowers.py https://mastodon.technology/@kde/102455343978152552 https://mastodon.social/@fsfe/102563322717544968
Both the toot
and account
dictionaries contain much more information. You can also use them to pull the content of the toot or maybe make a list of accounts the user follows. The point is, that is it. It is that simple to interact with Mastodon from scripts.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.