Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "threads-rs"
version = "0.1.0"
version = "0.1.1"
edition = "2024"
rust-version = "1.85"
description = "Rust client library for the Meta Threads API"
Expand Down
20 changes: 12 additions & 8 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ use crate::http::RequestBody;
pub struct TokenResponse {
/// The OAuth access token.
pub access_token: String,
/// Token type (usually "bearer").
pub token_type: String,
/// Token type (usually "bearer"). Not always returned by the API.
#[serde(default)]
pub token_type: Option<String>,
/// Token lifetime in seconds.
pub expires_in: Option<i64>,
/// App-scoped user ID.
Expand All @@ -31,8 +32,9 @@ pub struct TokenResponse {
pub struct LongLivedTokenResponse {
/// The long-lived access token.
pub access_token: String,
/// Token type (usually "bearer").
pub token_type: String,
/// Token type (usually "bearer"). Not always returned by the API.
#[serde(default)]
pub token_type: Option<String>,
/// Token lifetime in seconds (typically 5184000 for 60 days).
pub expires_in: i64,
}
Expand Down Expand Up @@ -193,7 +195,9 @@ impl Client {

let token_info = TokenInfo {
access_token: token_resp.access_token,
token_type: token_resp.token_type,
token_type: token_resp
.token_type
.unwrap_or_else(|| "bearer".to_string()),
expires_at: Utc::now() + chrono::Duration::seconds(expires_in),
user_id,
created_at: Utc::now(),
Expand Down Expand Up @@ -236,7 +240,7 @@ impl Client {

let token_info = TokenInfo {
access_token: long_resp.access_token,
token_type: long_resp.token_type,
token_type: long_resp.token_type.unwrap_or_else(|| "bearer".to_string()),
expires_at: Utc::now() + chrono::Duration::seconds(long_resp.expires_in),
user_id,
created_at: Utc::now(),
Expand Down Expand Up @@ -273,7 +277,7 @@ impl Client {

let token_info = TokenInfo {
access_token: long_resp.access_token,
token_type: long_resp.token_type,
token_type: long_resp.token_type.unwrap_or_else(|| "bearer".to_string()),
expires_at: Utc::now() + chrono::Duration::seconds(long_resp.expires_in),
user_id,
created_at: Utc::now(),
Expand Down Expand Up @@ -504,7 +508,7 @@ mod tests {
}"#;
let resp: TokenResponse = serde_json::from_str(json).unwrap();
assert_eq!(resp.access_token, "tok_abc");
assert_eq!(resp.token_type, "bearer");
assert_eq!(resp.token_type, Some("bearer".to_string()));
assert_eq!(resp.expires_in, Some(3600));
assert_eq!(resp.user_id, Some(12345));
}
Expand Down
Loading