xplore
X for Rust

💥 PRs are welcome.
❗We are still in the early development phase, so please be aware that the interfaces may evolve as we continue to refine the project.
Features
- Authentication with cookies
- Comprehensive user profile management
- Timeline retrieval
- Tweet interactions (like, retweet, post)
- Advanced search capabilities
- User relationship management (follow/unfollow)
Installation
[dependencies]
xplore = "0.1"
Quick start
use dotenv::dotenv;
use std::env;
use xplore::{IProfile, Xplore};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let user_id = xplore.get_user_id("elonmusk").await.unwrap();
println!("user id: {user_id}");
}
Get screen name's profile
use dotenv::dotenv;
use std::env;
use xplore::{IProfile, Xplore};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let screen_name = "elonmusk"; println!("Getting profile for: {screen_name}");
let profile = get_profile(&xplore, screen_name)
.await;
println!("Profile: {profile:#?}");
}
async fn get_profile(xplore: &Xplore, screen_name: &str) -> xplore::core::models::profile::Profile {
let profile = xplore.get_profile(screen_name)
.await
.expect("Failed to get profile");
profile
}
Get screen name's user ID
use dotenv::dotenv;
use std::env;
use xplore::{IProfile, Xplore};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let screen_name = "elonmusk"; println!("Getting profile for: {screen_name}");
let user_id = get_user_id(&xplore, screen_name)
.await;
println!("{screen_name}'s User ID: {user_id:?}");
}
async fn get_user_id(xplore: &Xplore, screen_name: &str) -> String {
let user_id = xplore.get_user_id(screen_name)
.await
.expect("Failed to get profile by ID");
user_id
}
Get pinned Tweet content
use dotenv::dotenv;
use std::env;
use xplore::{IProfile, Xplore, ITweet};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let screen_name = "elonmusk"; println!("Getting tweets for: {screen_name}");
let user_profile = xplore.get_profile(screen_name).await.unwrap();
let tweet = xplore.read_tweet(&user_profile.pinned_tweet_id.unwrap()).await.unwrap();
println!("Pinned Tweet ID: {:#?}", tweet.id);
println!("Pinned Tweet Text: {:#?}", tweet.text);
}
Search Tweet
use dotenv::dotenv;
use std::env;
use xplore::{search::SearchMode, ISearch, Xplore};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let tweets_response = xplore
.search_tweets("The Democratic Party", 2, SearchMode::Latest, None)
.await
.expect("Failed to search tweets");
for tweet in tweets_response.tweets {
println!("Tweet ID: {:#?}, Text: {:#?}", tweet.id, tweet.text);
}
}
Get Following and followers
use dotenv::dotenv;
use std::env;
use xplore::{IRel, Xplore};
#[tokio::main]
async fn main() {
dotenv().ok();
let cookie = env::var("X_COOKIE_STRING").expect("X_COOKIE_STRING");
let xplore = Xplore::new(&cookie).await.unwrap();
let user_id = "1222365222934962177";
let following_response = xplore.following(user_id, 1, None).await.expect("Failed to get following list");
println!("Following count: {}", following_response.1.unwrap_or("No next cursor".to_string()));
println!("Following profiles:");
for profile in following_response.0 {
println!("Following: {:#?}", profile.username);
}
let followers_response = xplore.followers(user_id, 1, None).await.expect("Failed to get followers list");
println!("Followers count: {}", followers_response.1.unwrap_or("No next cursor".to_string()));
println!("Followers profiles:");
for profile in followers_response.0 {
println!("Follower: {:#?}", profile.username);
}
}
Star History
