| title | Quickstart |
|---|---|
| sidebarTitle | Quickstart |
This example showcases how to quickly search for Posts using the XDK using Bearer Token authentication.
pip install xdk- Log in to the X Developer Portal.
- Create or select an app.
- Under "Keys and Tokens," generate a Bearer Token (app-only auth).
Create a file quickstart.py:
# 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"
response = client.posts.search_recent(query="api")
# Print the first Post's text
if response:
print(f"Latest Post: {response[0]['text']}")
else:
print("No Posts found.")Run it:
python quickstart.pyExpected Output:
Latest Post: Exciting updates on XDK Python SDK!
Troubleshooting: If you get a 401 error, double-check your Bearer Token. For rate limits (429), wait and retry.
- Explore Authentication to understand how to use Bearer Token (app-only) auth, OAuth 2.0 with PKCE (user context), and OAuth 1.0.
- Learn about Pagination for use-cases where you want large number of results returned without worrying about making multiple API calls.
- Dive into Streaming to learn how to work with real-time data.