[mastodon] try to get account IDs without access token
Try to query the public '/api/v1/accounts/lookup' endpoint and fall back to '/v1/accounts/search' if it returns an error. '/api/v1/accounts/lookup' is available since Mastodon v3.4.0. The version of an instance can be found at '/api/v1/instance'.
This commit is contained in:
@@ -227,6 +227,12 @@ class MastodonAPI():
|
||||
if username.startswith("id:"):
|
||||
return username[3:]
|
||||
|
||||
try:
|
||||
return self.account_lookup(username)["id"]
|
||||
except Exception:
|
||||
# fall back to account search
|
||||
pass
|
||||
|
||||
if "@" in username:
|
||||
handle = "@" + username
|
||||
else:
|
||||
@@ -246,6 +252,11 @@ class MastodonAPI():
|
||||
endpoint = "/v1/accounts/{}/following".format(account_id)
|
||||
return self._pagination(endpoint, None)
|
||||
|
||||
def account_lookup(self, username):
|
||||
endpoint = "/v1/accounts/lookup"
|
||||
params = {"acct": username}
|
||||
return self._call(endpoint, params).json()
|
||||
|
||||
def account_search(self, query, limit=40):
|
||||
"""Search for accounts"""
|
||||
endpoint = "/v1/accounts/search"
|
||||
|
||||
Reference in New Issue
Block a user