Danie1 / threads-api

Unofficial Python API for Meta's Threads App
https://pypi.org/project/threads-api/
MIT License
121 stars 16 forks source link

Multiple post replies on the same thread? #61

Closed idfalcon closed 1 year ago

idfalcon commented 1 year ago

I am currently trying to replicate a bot I saw on Twitter which has the following functionality:

// Reddit GET request to get the weeks top 5 posts in r/worldnews response = requests.get(f"https://www.reddit.com/r/worldnews/top.json?sort=top&t=week", headers={"User-Agent": "Mozilla/5.0"})

// Extract the top 5 threads from the response threads = response.json()["data"]["children"][:5]

// Create tweet message with the first post and thread posts tweet_msg = "Headlines for the week:" first_thread = threads[0] first_title = first_thread["data"]["title"] first_url = first_thread["data"]["url"] tweet_msg += f"No. 1: {first_title}\n{first_url}\n\n"

// Post the first tweet first_tweet = api.update_status(tweet_msg) print("First tweet posted successfully!")

// Reply to the first tweet with the thread posts for i, thread in enumerate(threads[1:], 2): title = thread["data"]["title"] url = thread["data"]["url"] reply_msg = f"No. {i}: {title}\n{url}\n\n" api.update_status(reply_msg, in_reply_to_status_id=first_tweet.id) print(f"Thread {i} posted successfully!")

print("All threads posted successfully!")

I am trying to find the command in the documentation to action the final step of self replying to the first tweet with the thread posts but I am unable to get any leads. Is this possible in the current state or is it a feature that needs to be implemented? Thanks for the pointers!

Danie1 commented 1 year ago

Hey, is this what you're looking for? https://github.com/Danie1/threads-api/blob/main/examples/private_api_examples.py#L164

idfalcon commented 1 year ago

I'll need to play around with it to get it to work but that might do the trick! Thanks for the work you've put in it!