First functional version

This commit is contained in:
VC
2023-11-08 16:12:41 +01:00
parent b3ba8637f8
commit 46ebbaadd0
3 changed files with 24 additions and 10 deletions

View File

@@ -14,7 +14,14 @@ pub struct Tweet {
}
#[derive(Deserialize, Debug)]
pub struct TweetResponse {}
pub struct TweetResponse {
pub data: TweetResponseData,
}
#[derive(Deserialize, Debug)]
pub struct TweetResponseData {
pub id: String,
}
/// This function returns the OAuth1 Token object from TwitterConfig
fn get_token(config: &TwitterConfig) -> Token {
@@ -39,14 +46,14 @@ pub async fn post_tweet(
_medias: &[u64],
) -> Result<u64, Box<dyn Error>> {
let uri = "https://api.twitter.com/2/tweets";
let token = get_token(config);
let empty_request = EmptyRequest {}; // Why? Because fuck you, thats why!
let token = get_token(config);
let tweet = Tweet {
text: content.to_string(),
};
let client = Client::new();
let res = client
.post(uri)
.header(
@@ -55,9 +62,9 @@ pub async fn post_tweet(
)
.json(&tweet)
.send()
.await?
.json::<TweetResponse>()
.await?;
println!("{:?}", res.text().await.unwrap());
Ok(0)
Ok(res.data.id.parse::<u64>().unwrap())
}