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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
sourcepub fn save_session(&mut self) -> Result<()>
pub fn save_session(&mut self) -> Result<()>
Examples found in repository?
examples/simple.rs (line 35)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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)
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
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cookies_path = PathBuf::from("cookies.json");
let username = std::env::var("USERNAME")?;
let password = std::env::var("PASSWORD")?;
debug!("username: {username}");
debug!("password: {password}");
let mut api = x_api_rs::TwAPI::new(Some(cookies_path.clone()))?;
if !cookies_path.exists() {
let result = api.login(&username, &password, "", None).await;
match result {
Err(err) => {
let error = err.downcast_ref::<SuspiciousLoginError>().unwrap();
println!("Enter your username (eg. @user): ");
let username = read_string();
api.login(&username, &password, "".into(), Some(error.1.clone())).await?;
}
Ok(_) => {}
}
api.save_session().unwrap();
}
// always call this for extract csrf
let is_logged_in = api.is_logged_in().await?;
println!("is logged: {is_logged_in}");
let user_id = api.me_rest_id().await?;
let res = api.get_following_ids(user_id.to_string(), -1).await?;
debug!("res is {res:?}");
let ids = res.entries.iter().map(|v| v.as_i64().unwrap_or_default().to_string()).collect();
let res = api.users_lookup(ids).await?;
debug!("res is {res:?}");
// loop {
// let pagination = api.get_friends(user_id, true, Some(cursor.into()))?;
// cursor = pagination.cursor.clone();
// debug!("Found {:?} following", pagination.entries.len());
// if !pagination.has_more {
// break;
// }
// }
Ok(())
}
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