nanos / FediFetcher

FediFetcher is a tool for Mastodon that automatically fetches missing replies and posts from other fediverse instances, and adds them to your own Mastodon instance.
https://blog.thms.uk/fedifetcher?utm_source=github
MIT License
309 stars 233 forks source link

FediFetcher crashes when using multiple tokens (admin:read:accounts scope) #144

Closed paviro closed 3 months ago

paviro commented 3 months ago

Hi! First of all thank you for your awesome work!

I just added a user second user token from a friend using my instance and FediFetcher crashed with:

2024-07-05 12:26:30 CEST: Job failed after 0:12:10.132080.
Traceback (most recent call last):
  File "/home/mastodon/FediFetcher/find_posts.py", line 1652, in <module>
    reply_toots = get_all_reply_toots(
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/mastodon/FediFetcher/find_posts.py", line 452, in get_all_reply_toots
    reply_toots = list(
                  ^^^^^
  File "/home/mastodon/FediFetcher/find_posts.py", line 453, in <genexpr>
    itertools.chain.from_iterable(
                                 ^
  File "/home/mastodon/FediFetcher/find_posts.py", line 437, in get_active_user_ids
    raise Exception(
Exception: Error getting user IDs on server whisper.tf. Status code: 403. Make sure you have the admin:read:accounts scope enabled for your access token.

The first token (mine) has the admin:read:accounts enabled. My friends is just a normal read token via getauth.thms.uk. Is there anything I am doing wrong or need to take into account when using two tokens?

nanos commented 3 months ago

You will need to set reply-interval-in-hours to 0, if one ore more users you are fetching for isn't an admin account.

The reason for this is that all options you set apply to all access-tokens you have supplied. As such, in order for this to work, you'd need both users to be admins, and both users to have the admin:read:accounts scope enabled for the token.

paviro commented 3 months ago

Alright thanks! Would it make sense to store the info if a token is admin or not and only do these things for the admin token? Or would that be out of scope for the project?

nanos commented 3 months ago

Yeah, it's a tough one. Because there is also the question of what happens, if (for example) one user has enabled the correct scopes to fetch lists, and the other has not?

I guess ideally we'd want to define settings on a per-access-token basis. Something like:

{
  "server": "your.mastodon.server",
  "tokens": [
    {
      "access_token": "Your access token",
      "home-timeline-length": 200,
      "reply-interval-in-hours": 24,
      "from-notifications": 1,
      "from-lists": 1
    },
    {
      "access_token": "Your friend's access token",
      "home-timeline-length": 200,
      "from-notifications": 1
    }
  ]
}

I wouldn't say it's out of scope. But it's not a priority at the moment, as there simply doesn't appear to be the demand for it, and my own time is limited.

If you (or someone else) wanted to provide a backwards compatible PR I'd happy accept that though.

paviro commented 3 months ago

That makes sense! Thank you for your input! I'll see if I find the time to look into it at some point.