0

My objective is to perform a search of Mastodon statuses and return the content (i.e. the text) of any status that matches. The docs suggest I can do this. Can I actually do this?

My python code is

import requests

url = 'https://<server>/api/v2/search'
auth = {'Authorization': 'Bearer <token>'}
params = {'q': '<keyword>', 'type':'statuses'}

response = requests.get(url, data=params, headers=auth)

First issue: I get the following response (no matter what keyword I choose and even when my keyword clearly appears in a recent status):

{'accounts': [], 'statuses': [], 'hashtags': []}

Second issue: If I don't restrict the search to statuses, I get results! But they are not what I expect. There's no content key :( While the example results do contain a content key, which was my goal.

{'accounts': [], 'statuses': [], 'hashtags': [{'name': 'hiring', 'url': 'https://data-folks.masto.host/tags/hiring', 'history': [{'day': '1675814400', 'accounts': '5', 'uses': '5'}, {'day': '1675728000', 'accounts': '10', 'uses': '13'}, {'day': '1675641600', 'accounts': '7', 'uses': '7'}, {'day': '1675555200', 'accounts': '6', 'uses': '6'}, {'day': '1675468800', 'accounts': '3', 'uses': '3'}, {'day': '1675382400', 'accounts': '5', 'uses': '6'}, {'day': '1675296000', 'accounts': '9', 'uses': '9'}], 'following': False}]}

Thanks for any help! I'm a beginner and truly appreciate it.

loz
  • 43
  • 5

1 Answers1

3

This question was answered for me by the user trwnh over on Mastodon's github discussions, so I am copying it here:

"Full-text search across all statuses is not supported. If your server has configured the optional Elasticsearch backend, then you can perform limited full-text search against your own posts, favourites, and bookmarks -- basically, only posts relevant to you. To obtain content based on a keyword, you must use hashtags."

loz
  • 43
  • 5