-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathchannel_information_custom.rs
66 lines (60 loc) · 2.22 KB
/
channel_information_custom.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use twitch_api::{helix, types, HelixClient};
use twitch_oauth2::{AccessToken, UserToken};
fn main() {
use std::error::Error;
if let Err(err) = run() {
println!("Error: {err}");
let mut e: &'_ dyn Error = err.as_ref();
while let Some(cause) = e.source() {
println!("Caused by: {cause}");
e = cause;
}
}
}
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let _ = dotenvy::dotenv();
let mut args = std::env::args().skip(1);
let client: HelixClient<reqwest::Client> = HelixClient::default();
let token = std::env::var("TWITCH_TOKEN")
.ok()
.or_else(|| args.next())
.map(AccessToken::new)
.expect("Please set env: TWITCH_TOKEN or pass token as first argument");
let token = UserToken::from_existing(&client, token, None, None).await?;
let resp = client
.req_get_custom(
helix::channels::GetChannelInformationRequest::broadcaster_ids(&token.user_id),
&token,
)
.await
.expect("oops");
let channel: Vec<CustomChannelInformation> = resp.data()?;
println!("Stream information:\n{channel:#?}");
Ok(())
}
/// Return Values for Get Channel Information
///
/// [`get-channel-information`](https://dev.twitch.tv/docs/api/reference#get-channel-information)
#[derive(PartialEq, Eq, serde_derive::Deserialize, serde_derive::Serialize, Debug, Clone)]
pub struct CustomChannelInformation<'a> {
/// Twitch User ID of this channel owner
pub broadcaster_id: &'a types::UserIdRef,
/// Twitch User login of this channel owner
pub broadcaster_login: &'a types::UserNameRef,
/// Twitch user display name of this channel owner
pub broadcaster_name: &'a types::DisplayNameRef,
/// Current game ID being played on the channel
pub game_id: &'a types::CategoryIdRef,
/// Name of the game being played on the channel
pub game_name: types::CategoryId,
/// Language of the channel
pub broadcaster_language: &'a str,
/// Title of the stream
pub title: &'a str,
/// Description of the stream
#[serde(default)]
pub description: &'a str,
/// Stream delay in seconds
pub delay: i64,
}