Crates.io | xv2api |
lib.rs | xv2api |
version | 0.1.1 |
created_at | 2025-06-28 13:57:16.160993+00 |
updated_at | 2025-06-28 13:57:16.160993+00 |
description | X/Twitter V2 API Library |
homepage | https://hack.ink/xv2api |
repository | https://github.com/hack-ink/xv2api |
max_upload_size | |
id | 1729851 |
size | 106,570 |
Set up the required environment variables for X/Twitter API access:
# Required: Your X/Twitter App Client ID and Secret
export X_CLIENT_ID="your_client_id_here"
export X_CLIENT_SECRET="your_client_secret_here"
# Optional: Refresh token to avoid re-authentication
export X_REFRESH_TOKEN="your_refresh_token_here"
use xv2api::{Api, tweets::ApiTweet};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize API client from environment variables.
let api = Api::from_env();
// Post a tweet.
let resp = api.tweet("Hello from XV2API! 🦀".to_string()).await?;
println!("Response: {resp:?}");
println!("Tweet posted successfully!");
Ok(())
}
XV2API follows a modular architecture designed for extensibility and maintainability:
xv2api/
├── src/
│ ├── lib.rs # Main API client and core functionality
│ ├── auth.rs # OAuth 2.0 authentication module
│ ├── tweets.rs # Tweet-related API endpoints
│ └── error.rs # Error types and handling
├── Cargo.toml # Project configuration and dependencies
└── README.md # This documentation
Api
: Main client struct handling HTTP requests and authenticationAuthenticator
: OAuth 2.0 flow management with token cachingApiTweet
: Trait defining tweet-related operationsError
: Comprehensive error handling for various failure scenariosIf you find this project helpful and would like to support its development, you can buy me a coffee!
Your support is greatly appreciated and motivates me to keep improving this project.
bc1pedlrf67ss52md29qqkzr2avma6ghyrt4jx9ecp9457qsl75x247sqcp43c
0x3e25247CfF03F99a7D83b28F207112234feE73a6
156HGo9setPcU2qhFMVWLkcmtCEGySLwNqa3DaEiYSWtte4Y
Thank you for your support!
We would like to extend our heartfelt gratitude to the following projects and contributors:
Licensed under GPL-3.0.