Overview
This guide walks you through creating and posting your first tweet using XDK Python. You’ll learn how to authenticate, create a post, and handle the response.Make sure you’ve completed the installation and have your API credentials ready.
Your First Tweet in 3 Steps
Complete Working Example
Here’s a complete script that posts a tweet:example.py
Advanced Examples
Post with Media
Create a tweet with attached images:Reply to a Tweet
Post a reply to an existing tweet:Post with a Poll
Create a tweet with a poll:Quote Tweet
Quote an existing tweet:Reading Tweets
Get Tweet by ID
Search Recent Tweets
Get Multiple Tweets
Delete a Tweet
Error Handling
Always handle potential errors when making API requests:Common Response Fields
When you create a post, the response contains:response.data.id- The unique ID of the created tweetresponse.data.text- The text content of the tweetresponse.errors- Any errors that occurred (if applicable)
Rate Limits
Next Steps
Now that you’ve posted your first tweet, explore more features:Authentication
Learn about OAuth flows and token management
API Reference
Explore all available endpoints and methods
Users API
Work with user profiles and relationships
Streaming
Set up real-time tweet streaming
Troubleshooting
Authentication errors
Authentication errors
If you get authentication errors:
- Verify your credentials are correct
- Check that your access token hasn’t expired
- Ensure your app has the correct permissions
- For OAuth1, verify all four credentials (API key, secret, token, token secret)
Rate limit errors
Rate limit errors
If you hit rate limits:
- Check the response headers for rate limit info
- Implement exponential backoff
- Consider upgrading your API access level
Validation errors
Validation errors
If your request is rejected:
- Check tweet text length (max 280 characters)
- Verify media IDs are valid
- Ensure poll options meet requirements (2-4 options)
- Check that referenced tweet IDs exist