pub struct TwAPI { /* private fields */ }
Implementations§
Source§impl TwAPI
impl TwAPI
Sourcepub fn new(session_path: Option<PathBuf>) -> Result<TwAPI>
pub fn new(session_path: Option<PathBuf>) -> Result<TwAPI>
Examples found in repository?
examples/simple.rs (line 22)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
pub async fn get_flow_token(&mut self, data: Value) -> Result<Option<Flow>>
pub async fn before_password_steps(&mut self, username: String) -> Result<Flow>
Sourcepub async fn login(
&mut self,
username: &str,
password: &str,
confirmation: &str,
latest_flow: Option<Flow>,
) -> Result<Option<Flow>>
pub async fn login( &mut self, username: &str, password: &str, confirmation: &str, latest_flow: Option<Flow>, ) -> Result<Option<Flow>>
Examples found in repository?
examples/simple.rs (line 24)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Sourcepub async fn is_logged_in(&mut self) -> Result<bool>
pub async fn is_logged_in(&mut self) -> Result<bool>
Examples found in repository?
examples/simple.rs (line 38)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Sourcepub fn save_session(&mut self) -> Result<()>
pub fn save_session(&mut self) -> Result<()>
Examples found in repository?
examples/simple.rs (line 35)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Source§impl TwAPI
impl TwAPI
pub async fn me(&self) -> Result<Value>
pub fn me_following(&mut self)
Sourcepub async fn me_rest_id(&mut self) -> Result<i64, Box<dyn Error>>
pub async fn me_rest_id(&mut self) -> Result<i64, Box<dyn Error>>
Examples found in repository?
examples/simple.rs (line 41)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Source§impl TwAPI
impl TwAPI
pub async fn user_id( &mut self, username: String, ) -> Result<String, Box<dyn Error>>
pub async fn get_friends( &mut self, user_id: i64, following: bool, start_cursor: Option<String>, ) -> Result<PaginationResponse, Box<dyn Error>>
pub async fn get_follower_ids( &mut self, user_id: String, cursor: i32, ) -> Result<PaginationResponse>
Sourcepub async fn get_following_ids(
&mut self,
user_id: String,
cursor: i32,
) -> Result<PaginationResponse>
pub async fn get_following_ids( &mut self, user_id: String, cursor: i32, ) -> Result<PaginationResponse>
Examples found in repository?
examples/simple.rs (line 42)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Sourcepub async fn users_lookup(&mut self, ids: Vec<String>) -> Result<Vec<Value>>
pub async fn users_lookup(&mut self, ids: Vec<String>) -> Result<Vec<Value>>
Examples found in repository?
examples/simple.rs (line 45)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16
17 let cookies_path = PathBuf::from("cookies.json");
18 let username = std::env::var("USERNAME")?;
19 let password = std::env::var("PASSWORD")?;
20 debug!("username: {username}");
21 debug!("password: {password}");
22 let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
23 if !cookies_path.exists() {
24 let result = api.login(&username, &password, "", None).await;
25 match result {
26 Err(err) => {
27 let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
28 println!("Enter your username (eg. @user): ");
29 let username = read_string();
30 api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
31 }
32 Ok(_) => {}
33 }
34
35 api.save_session().unwrap();
36 }
37 // always call this for extract csrf
38 let is_logged_in = api.is_logged_in().await?;
39 println!("is logged: {is_logged_in}");
40
41 let user_id = api.me_rest_id().await?;
42 let res = api.get_following_ids(user_id.to_string(), -1).await?;
43 debug!("res is {res:?}");
44 let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
45 let res = api.users_lookup(ids).await?;
46 debug!("res is {res:?}");
47 // loop {
48 // let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
49 // cursor = pagination.cursor.clone();
50 // debug!("Found {:?} following", pagination.entries.len());
51 // if !pagination.has_more {
52 // break;
53 // }
54 // }
55 Ok(())
56
57}
Auto Trait Implementations§
impl Freeze for TwAPI
impl !RefUnwindSafe for TwAPI
impl Send for TwAPI
impl Sync for TwAPI
impl Unpin for TwAPI
impl !UnwindSafe for TwAPI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more