Crates.io | twapi |
lib.rs | twapi |
version | 0.7.0 |
source | src |
created_at | 2018-03-06 00:32:36.683071 |
updated_at | 2021-03-26 08:39:53.89433 |
description | A simple Twitter library. This is easy for customize. |
homepage | |
repository | https://github.com/aoyagikouhei/twapi-rs |
max_upload_size | |
id | 54036 |
size | 29,562 |
A simple Twitter library. This is easy for customize.
twapi-rs* is is a simple Twitter library. This is easy for customize.
use twapi::Twapi;
#[tokio::main]
async fn main() {
// Application Only Authentication Sample
let consumer_key = "xxx";
let consumer_secret = "xxx";
let applicaiton_auth = twapi::ApplicationAuth::new(
&twapi::oauth2::get_bearer_token(consumer_key, consumer_secret).await.unwrap()
);
let res = applicaiton_auth.get_search_tweets(
&vec![("q", "新宿"), ("count", "2")]
).await.unwrap();
println!("{:?}", res);
// Custmize Sample. Any API Executable!
let res: serde_json::Value = applicaiton_auth.get(
"https://api.twitter.com/1.1/statuses/user_timeline.json",
&vec![("screen_name", "aoyagikouhei"), ("count", "2")]
).await.unwrap().json().await.unwrap();
println!("{:?}", res);
// JSON Sample
let user_auth = twapi::UserAuth::new(
"xxx",
"xxx",
"xxx",
"xxx"
);
let data = r#"{
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "19522946"
},
"message_data": {
"text": "予定表〜①ハンカクだ!"
}
}
}
}"#;
let v : serde_json::Value = serde_json::from_str(data).unwrap();
let res = user_auth.post_direct_messages_events_new(&v).await;
println!("{:?}", res);
// Media Upload
let res = user_auth.post_media_upload_chunk("test.mp4", "video/mp4", "tweet_video", None).await;
println!("{:?}", res);
}