982
edits
(→Discord: new section) |
(→Test Instance: new section) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
* API Documentation: https://docs.joinmastodon.org/api/ (scroll down, the different API endpoints are listed in the TOC under API Methods) | |||
== Code Samples == | |||
Using [[Depends On::Mastodon.py]], and see https://git.jon-e.net/jonny/masto-gitsocial-bridge for more examples from a sort of infrastructural shitpost | |||
* Interacting with masto: https://git.jon-e.net/jonny/masto-gitsocial-bridge/src/branch/main/masto_git_bridge/bot.py | |||
* Post model: https://git.jon-e.net/jonny/masto-gitsocial-bridge/src/branch/main/masto_git_bridge/post.py | |||
=== Make Masto Token === | |||
Most of the interesting parts of the API need you to log in underneath an account, and so for that you need to make an auth token: | |||
From your masto instance's homepage... | |||
* Preferences (in hamburger menu top right if page is narrow) | |||
* Development tab | |||
* New Application | |||
The bot needs permissions (I'm honestly not sure you need to give all of <code>read</code>, but | |||
Mastodon.py's <code>me()</code> method seems to need a lot of them. idk.) | |||
- <code>read</code> | |||
- <code>write:lists</code> - the bot only streams your posts by making a list with just you on it | |||
- <code>write:statuses</code> - to xpost, dummy! | |||
Then copy the resulting access token for use in configuration... | |||
<syntaxhighlight lang="python"> | |||
from mastodon import Mastodon | |||
client = Mastodon( | |||
access_token=MASTO_TOKEN, | |||
api_base_url=MASTO_URL | |||
) | |||
</syntaxhighlight> | |||
'''''hacker voice:''''' ''I'm in'' | |||
=== Post! === | |||
Posting v easy. | |||
<syntaxhighlight lang="python"> | |||
post = client.status_post("my post") | |||
</syntaxhighlight> | |||
And then to thread: | |||
<syntaxhighlight lang="python"> | |||
second_post = client.status_post( | |||
"second post", | |||
in_reply_to_id=post | |||
) | |||
</syntaxhighlight> | |||
=== Listen to a list of users === | |||
You can also listen to all the accounts that your profile follows, but usually on public instances you want to be respectful and have some sort of opt-in mechanism, and usually that means making a list of accounts that follow you. | |||
Assuming you've already made a list named "my_list"... (see https://git.jon-e.net/jonny/masto-gitsocial-bridge/src/commit/6c65eaa30180dfa1a5995cead10d8ce3f9b2af49/masto_git_bridge/bot.py#L91-L95 for an example of making a list, in this case just with the ID of the bot on it, but you can also list accounts following the bot using [https://mastodonpy.readthedocs.io/en/stable/#mastodon.Mastodon.account_followers account_followers()]) | |||
Subclass the StreamListener and override its <code>on_update</code> method to handle new statuses. Then initialize it using the client we logged in with above | |||
<syntaxhighlight lang="python"> | |||
from mastodon import StreamListener | |||
class Listener(StreamListener): | |||
def on_update(self, status:dict): | |||
# do something.... | |||
pass | |||
# get our list | |||
my_list = [l for l in client.lists() if l.get('title', '') == 'my_list'][0] | |||
# start streaming our list, responding using on_update when there's a post | |||
listener = Listener() | |||
client.stream_list( | |||
my_list['id'], | |||
listener = listener | |||
) | |||
</syntaxhighlight> | |||
== Discord == | == Discord == | ||
Line 8: | Line 91: | ||
|Text=Excuse me let me be a good role model on continuous archiving. One of the reasons I am excited about academics adopting [[Mastodon]] is because [[ActivityPub]] is built on [[Linked Data]], which i think inspires the possibility for fundamentally new modes of scholarly communication. I have written about this in the past ([[Has DOI::10.48550/arXiv.2209.07493]], but will do my best to decenter my own ideas except for when I am using them as a demonstration for others as part of a demonstration of using the technology developed for the workshop | |Text=Excuse me let me be a good role model on continuous archiving. One of the reasons I am excited about academics adopting [[Mastodon]] is because [[ActivityPub]] is built on [[Linked Data]], which i think inspires the possibility for fundamentally new modes of scholarly communication. I have written about this in the past ([[Has DOI::10.48550/arXiv.2209.07493]], but will do my best to decenter my own ideas except for when I am using them as a demonstration for others as part of a demonstration of using the technology developed for the workshop | ||
|Link=https://discord.com/channels/1029514961782849607/1037261659368067072/1037278126918619188 | |Link=https://discord.com/channels/1029514961782849607/1037261659368067072/1037278126918619188 | ||
}} | |||
== Test Instance == | |||
{{Message | |||
|Author=sneakers-the-rat | |||
|Avatar=https://cdn.discordapp.com/avatars/305044217393053697/2970b22bd769d0cd0ee1de79be500e85.png?size=1024 | |||
|Date Sent=22-11-12 20:53:17 | |||
|Channel=mod-requests | |||
|Text=OK we have a testing [[Mastodon#Test Instance]] server up and running at https://masto.synthesis-infrastructures.wiki | |||
- since I am not going to bother setting up sending emails from the test instance, I need to manually bypass the email verification step for any accounts that are registered. If you want to make an account just for funzies, send me a DM here with the email you used to sign up with and i'll bypass it for you. | |||
- this is not secure! at all! I did nothing to secure it! seriously this is just used for testing purposes! When the workshop ends I'll shut it down and archive the toots as static pages! | |||
|Link=https://discord.com/channels/1029514961782849607/1032530251944833054/1041093349760839761 | |||
}} | }} |