| Crates.io | fitbit-rs |
| lib.rs | fitbit-rs |
| version | 0.1.0 |
| created_at | 2025-03-30 13:16:34.445089+00 |
| updated_at | 2025-03-30 13:16:34.445089+00 |
| description | A Rust client for the Fitbit API |
| homepage | |
| repository | https://github.com/yourusername/fitbit-rs |
| max_upload_size | |
| id | 1612359 |
| size | 118,040 |
A work in progress Rust client library for the Fitbit API. Currently implemented are fetching sleep data and activity summaries.
Add the following to your Cargo.toml:
[dependencies]
fitbit-rs = "0.1.0"
use fitbit_rs::{FitbitClient, FitbitClientTrait};
use chrono::NaiveDate;
fn main() -> Result<(), fitbit_rs::FitbitError> {
// Get access token (typically from environment or config file)
let access_token = "your_access_token".to_string();
// Create a client
let client = FitbitClient::new(access_token);
// Fetch today's sleep data
let today = chrono::Local::now().date_naive();
let sleep_data = client.fetch_sleep_data(today)?;
println!("Sleep duration: {} minutes", sleep_data.summary.total_minutes_asleep);
// Fetch today's activity summary
let activity = client.fetch_activity_summary(today)?;
println!("Steps today: {}", activity.summary.steps);
Ok(())
}
The library provides utilities for storing and retrieving access tokens:
use fitbit_rs::access_token::{get_access_token, store_access_token};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Store an access token
store_access_token("your_new_access_token")?;
// Retrieve the stored access token
let token = get_access_token()?;
println!("Retrieved token: {}", token);
Ok(())
}
To use this library, you need a Fitbit API access token. You can get one by:
store_access_token function or pass it directly to the clientFor more detailed documentation, see the API Documentation.
This project is licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.