twitter_v2/lib.rs
1//! [](https://developer.twitter.com/en/docs/twitter-api)
2//!
3//! Supports all of the Twitter v2 API endpoints, but many remain fairly untested
4//! due to the complexity of the API and time restraints. PRs and Issues are very welcome!
5//! As this repo currently has limited documentation, please check out the amazing [Twitter API v2
6//! Docs](https://developer.twitter.com/en/docs/api-reference-index#twitter-api-v2) for information.
7//!
8//! # Features
9//!
10//! * **oauth2**: Included by default. See the examples for how to use.
11//! * **native-tls**: Use `native-tls` as TLS backend (default)
12//! * **rustls-tls**: Use `rustls` as TLS backend
13//!
14//! # Example
15//!
16//! ```
17//! use twitter_v2::TwitterApi;
18//! use twitter_v2::authorization::{Oauth2Token, BearerToken};
19//! use twitter_v2::query::{TweetField, UserField};
20//! # use time::macros::datetime;
21//!
22//! # #[tokio::main]
23//! # async fn main() -> twitter_v2::Result<()> {
24//! let auth = BearerToken::new(std::env::var("APP_BEARER_TOKEN").unwrap());
25//! let tweet = TwitterApi::new(auth)
26//! .get_tweet(1261326399320715264)
27//! .tweet_fields([TweetField::AuthorId, TweetField::CreatedAt])
28//! .send()
29//! .await?
30//! .into_data()
31//! .expect("this tweet should exist");
32//! assert_eq!(tweet.id, 1261326399320715264);
33//! assert_eq!(tweet.author_id.unwrap(), 2244994945);
34//! assert_eq!(tweet.created_at.unwrap(), datetime!(2020-05-15 16:03:42 UTC));
35//!
36//! # let stored_oauth2_token = std::fs::read_to_string("./.oauth2_token.json").unwrap();
37//! let auth: Oauth2Token = serde_json::from_str(&stored_oauth2_token)?;
38//! let my_followers = TwitterApi::new(auth)
39//! .with_user_ctx()
40//! .await?
41//! .get_my_followers()
42//! .user_fields([UserField::Username])
43//! .max_results(20)
44//! .send()
45//! .await?
46//! .into_data();
47//! # Ok(())
48//! # }
49//! ```
50
51#[cfg(not(any(feature = "rustls-tls", feature = "native-tls")))]
52compile_error!("Either `rustls-tls` or `native-tls` feature must be selected");
53
54#[cfg(feature = "oauth2")]
55pub extern crate oauth2;
56
57pub mod api;
58pub mod api_result;
59pub mod authorization;
60pub mod data;
61pub mod error;
62pub mod id;
63pub mod meta;
64pub mod query;
65pub mod requests;
66mod utils;
67
68pub use self::{
69 api::{TwitterApi, TwitterApiWithUserCtx},
70 api_result::{ApiError, ApiPayload, ApiResponse, ApiResult},
71 authorization::Authorization,
72 data::{Media, Place, Poll, Space, Tweet, User},
73 error::{Error, Result},
74};
75
76pub mod prelude {
77 pub use crate::api_result::PaginableApiResponse;
78 pub use crate::authorization::Authorization;
79 pub use crate::id::{IntoNumericId, IntoStringId};
80 pub use crate::meta::PaginationMeta;
81}