Created
November 12, 2022 17:07
-
-
Save ekusiadadus/5f2ee871500cf575c5ac77a74b13c916 to your computer and use it in GitHub Desktop.
Rust Twitter API v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// write Twitter API 2 get tweets about ekusiadadus using tokio with BEARER_TOKEN | |
use dotenv::dotenv; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
dotenv().ok(); | |
let bearer_token = std::env::var("BEARER_TOKEN").expect("BEARER_TOKEN not set"); | |
let client = reqwest::Client::new(); | |
let uri = "https://api.twitter.com/2/tweets/search/recent?query=ekusiadadus"; | |
let response = client | |
.get(uri) | |
.bearer_auth(bearer_token) | |
.send() | |
.await? | |
.error_for_status()?; | |
let body = response.text().await?; | |
println!("{}", body); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment