#garmin #oauth2 #client #fitness #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

#934 in Authentication

Download history 34/week @ 2024-07-25 10/week @ 2024-08-01 6/week @ 2024-09-19 3/week @ 2024-09-26

93 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

~16–31MB
~460K SLoC