url
or live_id
or channel_id
rust
// pattern 1
let mut client = LiveClientBuilder::new()
.url("https://www.youtube.com/watch?v=jfKfPfyJRdk".to_string())
.unwrap()
.build();
// pattern 2
let mut client = LiveChatClientBuilder::new()
.live_id("jfKfPfyJRd".to_string())
.build();
// pattern 3
let mut client = LiveChatClientBuilder::new()
.channel_id("UCHVXbQzkl3rDfsXWo8xi2qw".to_string())
.build();
rust
let mut client = LiveChatClientBuilder::new()
.url("https://www.youtube.com/watch?v=Dx5qFachd3A".to_string())
.unwrap()
.on_start(|_live_id| {})
.on_error(|_err| {})
.on_chat(|_chat_item| {})
.on_end(|| {})
.build();
rust
client.start().await.unwrap();
rust
client.execute().await;
execute
intervally if you want to fetch comments in real timeExample using tokio ```rust use std::time::Duration;
use tokio::{task, time}; use youtubechat::livechat::LiveChatClientBuilder;
async fn main() { let mut client = LiveChatClientBuilder::new() .url("https://www.youtube.com/watch?v=jfKfPfyJRdk".tostring()) .unwrap() .onchat(|chatitem| println!("{:?}", chatitem.message)) .onerror(|error| eprintln!("{:?}", error)) .build(); client.start().await.unwrap(); let forever = task::spawn(async move { let mut interval = time::interval(Duration::frommillis(3000)); loop { interval.tick().await; client.execute().await; } });
forever.await.unwrap();
} ```