# Import the client
from xdk import Client
# Replace with your actual Bearer Token
client = Client(bearer_token="YOUR_BEARER_TOKEN_HERE")
# Fetch recent Posts mentioning "api"
# search_recent returns an Iterator, so iterate over it
for page in client.posts.search_recent(query="api", max_results=10):
if page.data and len(page.data) > 0:
# Access first Post - Pydantic models support both attribute and dict access
first_post = page.data[0]
post_text = first_post.text if hasattr(first_post, 'text') else first_post.get('text', '')
print(f"Latest Post: {post_text}")
break
else:
print("No Posts found.")
break