Skip to main content
This example showcases how to quickly search for Posts using the XDK using Bearer Token authentication.

Step 1: Install the SDK

Step 2: Get Your Bearer Token

  1. Log in to the X Developer Console.
  2. Create or select an app.
  3. Under “Keys and Tokens,” generate a Bearer Token (app-only auth).

Step 3: Write and Run Your First Script

Create a file quickstart.py:
Run it:
Expected Output:
Troubleshooting: If you get a 401 error, double-check your Bearer Token. For rate limits (429), wait and retry.

Next Steps

  • Explore Authentication to understand how to use Bearer Token (app-only) auth, OAuth 2.0 with PKCE (user context), and OAuth 1.0a (legacy user context).
  • 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. For detailed code examples using the Python XDK, check out our code samples GitHub repo.