#oauth2 #client #fitness #garmin #api-client

garmin_client

Provides an oauth2.0-capable client that interfaces with Garmin

7 releases

0.2.0 Feb 13, 2024
0.1.6 Jan 26, 2024

#657 in Authentication

Download history 20/week @ 2024-01-17 38/week @ 2024-01-24 22/week @ 2024-02-07 31/week @ 2024-02-14 20/week @ 2024-02-21 8/week @ 2024-02-28 1/week @ 2024-03-06 12/week @ 2024-03-13 15/week @ 2024-03-27 26/week @ 2024-04-03

53 downloads per month
Used in garmin_download

GPL-3.0 license

30KB
526 lines

Example Usage:

use std::collections::HashMap;
use garmin_client::GarminClient;
use chrono::NaiveDateTime;

fn main() {
    let args: Vec<String> = env::args().collect();

    // first need to login (hopefully that's obvious)
    let mut client = GarminClient::new();
    client.login(args[1], args[2]);

    // get endpoint for service
    let endpoint = "weight-service/weight/dateRange";

    let weight_date = "2023-01-01 00:00:00";
    let datetime = NaiveDateTime::parse_from_str(&weight_date, "%Y-%m-%d %H:%M:%S").unwrap();

    let params = HashMap::from([
        ("startDate", "2023-01-01"),
        ("endDate", "2023-01-01"),
        ("_", datetime.timestamp_millis().as_str())
    ]);

    let is_json_result = true;
    let filename = "weight.json";
    client.api_request(endpoint, Some(params), is_json_result, filename);
}

Recommend using garmin_download crate for more programmatic control, and otherwise demonstration of how to format various other API endpoints.

Note: this client uses basic session management to store session tokens. However, heuristics show that only one endpoint download is allowed for a given session (e.g., can only download specific sleep data for specific date for one session, but you can download sleep data for another date on the same session). Therefore to redownload the same file(s) from the same endpoints you'll need to delete the .garmin_session.json file saved after first logging in, or wait until that token expires.

Dependencies

~15–32MB
~478K SLoC