insta-rs 0.1.0

instagram private library
Documentation

Instagram data scraping library for Rust.

Example

use insta_rs::Instagram;

#[tokio::main]
async fn main() -> insta_rs::Result<()> {
    let client = Instagram::builder().build()?;

    let user = client.user("instagram").await?;
    println!("{} has {} followers", user.username, user.follower_count);

    Ok(())
}

Authentication

The client supports multiple authentication methods:

use insta_rs::{Instagram, SessionData};

# async fn example() -> insta_rs::Result<()> {
// anonymous access (limited)
let client = Instagram::builder().build()?;

// with credentials (auto-fetches csrf token)
let client = Instagram::builder()
    .id("username")
    .password("password")
    .build()?;
client.login().await?;

// with existing session
let session = SessionData::new("session_id", "csrf_token");
let client = Instagram::builder()
    .session(session)
    .build()?;
# Ok(())
# }

Fetching Data

use insta_rs::Instagram;

# async fn example() -> insta_rs::Result<()> {
let client = Instagram::builder().build()?;

// fetch user profile
let user = client.user("natgeo").await?;

// fetch a specific post
let post = client.media("ABC123xyz").await?;

// fetch reel data
let reel = client.reel("DEF456uvw").await?;

// fetch user posts with pagination
let mut cursor = None;
loop {
    let page = client.user_posts(&user.id, 12, cursor.as_deref()).await?;
    for post in &page.items {
        println!("{}: {} likes", post.shortcode, post.like_count);
    }
    if !page.has_next {
        break;
    }
    cursor = page.cursor;
}
# Ok(())
# }

Comments and Likes

use insta_rs::Instagram;

# async fn example() -> insta_rs::Result<()> {
let client = Instagram::builder().build()?;

// fetch comments on a post
let comments = client.comments("media_id", 50, None).await?;
for comment in &comments.items {
    println!("{}: {}", comment.owner.username, comment.text);
}

// fetch users who liked a post
let likers = client.likers("shortcode", 50, None).await?;
for liker in &likers.items {
    println!("{}", liker.username);
}
# Ok(())
# }

Search

use insta_rs::Instagram;

# async fn example() -> insta_rs::Result<()> {
let client = Instagram::builder().build()?;

let results = client.search("rust programming").await?;

for user in &results.users {
    println!("user: @{}", user.username);
}
for tag in &results.hashtags {
    println!("tag: #{} ({} posts)", tag.name, tag.media_count);
}
# Ok(())
# }