Skip to content

Instantly share code, notes, and snippets.

@ekusiadadus
Created November 12, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekusiadadus/5f2ee871500cf575c5ac77a74b13c916 to your computer and use it in GitHub Desktop.
Save ekusiadadus/5f2ee871500cf575c5ac77a74b13c916 to your computer and use it in GitHub Desktop.
Rust Twitter API v2
// 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