This repository was archived by the owner on Oct 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathexample.py
executable file
·47 lines (37 loc) · 1.57 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from threads_api.src.threads_api import ThreadsAPI
import asyncio
async def get_user_id_from_username():
threads_api = ThreadsAPI()
username = "zuck"
user_id = await threads_api.get_user_id_from_username(username)
if user_id:
print(f"The user ID for username '{username}' is: {user_id}")
else:
print(f"User ID not found for username '{username}'")
async def get_user_profile_threads():
threads_api = ThreadsAPI()
username = "zuck"
user_id = await threads_api.get_user_id_from_username(username)
if user_id:
threads = await threads_api.get_user_profile_threads(username, user_id)
print(f"The threads for user '{username}' are:")
for thread in threads:
print(f"Text: {thread['thread_items'][0]['post']['caption']} || Likes: {thread['thread_items'][0]['post']['like_count']}")
else:
print(f"User ID not found for username '{username}'")
async def get_user_profile():
threads_api = ThreadsAPI()
username = "zuck"
user_id = await threads_api.get_user_id_from_username(username)
if user_id:
user_profile = await threads_api.get_user_profile(username, user_id)
print(f"User profile for '{username}':")
print(f"Name: {user_profile['username']}")
print(f"Bio: {user_profile['biography']}")
print(f"Followers: {user_profile['follower_count']}")
else:
print(f"User ID not found for username '{username}'")
# Run the functions
asyncio.run(get_user_id_from_username())
asyncio.run(get_user_profile_threads())
asyncio.run(get_user_profile())