可參考上一篇教學獲取access_token和其他需要的東西
第一步
輸入
pip install threads-py \
-i https://test.pypi.org/simple \
--extra-index-url https://pypi.org/simple
然後
from threads_py import ThreadsClient
client = ThreadsClient(
user_id=str(secrets["user_id"]), # 你的用戶ID
access_token=str(secrets["access_token"]) #你的access_token
)
- 發佈文章
draft = client.create_post(text="Hello Threads!")
published = draft.publish()
- 發佈回覆
reply_draft = client.create_post(text="Thanks for reading")
reply = published.reply(reply_draft)
- 發佈帶照片的文章 帶tag的文章
image_draft = client.create_post(
text="Check out this image!",
image_url="https://http.cat/404.jpg",
topic_tag="http-cat", #tag
)
image_post = image_draft.publish()
- 發佈多照片/影片貼文
carousel_draft = client.create_carousel(
media_urls=[
("IMAGE", "https://http.cat/404.jpg"),
("IMAGE", "https://http.cat/502.jpg"),
("IMAGE", "https://http.cat/100.jpg")
],
text="My carousel post",
)
carousel_post = carousel_draft.publish()