From 3b63d969277757f0da2e627dc2b871268be1683f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 30 Jan 2026 05:23:59 +0000 Subject: [PATCH] Complete Details section in documentation Added detailed instructions for "OAuth Authentication" and "Accessing User Data" in `withings-doc/docs/index.md`. - Documented the OAuth 1.0a flow using `Authenticator`. - Documented how to use `WithingsClient` to fetch data. - Provided code examples for setting up credentials, token exchange, and API calls. Co-authored-by: antarr <974295+antarr@users.noreply.github.com> --- withings-doc/docs/index.md | 59 +++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/withings-doc/docs/index.md b/withings-doc/docs/index.md index 03e5d9e..e084bb4 100644 --- a/withings-doc/docs/index.md +++ b/withings-doc/docs/index.md @@ -5,7 +5,64 @@ You can install the latest version using Nuget `Install-Package Withings.NET` -## Details (TODO) +## Details #### OAuth Authentication +Withings.NET handles the OAuth 1.0a authentication flow required by the Withings API. + +1. **Setup Credentials** + + First, configure your Withings API credentials. + ```csharp + var credentials = new WithingsCredentials(); + credentials.SetCallbackUrl("YOUR_CALLBACK_URL"); + credentials.SetConsumerProperties("YOUR_CONSUMER_KEY", "YOUR_CONSUMER_SECRET"); + ``` + +2. **Get Request Token** + + Instantiate the `Authenticator` and obtain a request token. This token is used to generate the user authorization URL. + ```csharp + var authenticator = new Authenticator(credentials); + var requestToken = await authenticator.GetRequestToken(); + var authorizationUrl = authenticator.UserRequestUrl(requestToken); + + // Redirect the user to authorizationUrl + ``` + +3. **Exchange for Access Token** + + After the user authorizes your app, they will be redirected to your callback URL with `oauth_verifier` and `userid`. Use the verifier to exchange the request token for an access token. + ```csharp + // In your callback handler + var verifier = Request.QueryString["oauth_verifier"]; + var accessToken = await authenticator.ExchangeRequestTokenForAccessToken(requestToken, verifier); + + // Store these securely + var oauthToken = accessToken.Key; + var oauthSecret = accessToken.Secret; + var userId = Request.QueryString["userid"]; + ``` + #### Accessing User Data +Once you have the `oauthToken`, `oauthSecret`, and `userId`, you can access the user's data using the `WithingsClient`. + +1. **Initialize Client** + ```csharp + var client = new WithingsClient(credentials); + ``` + +2. **Fetch Data** + + Call the available methods to retrieve data. For example, to get activity measures: + ```csharp + var activity = await client.GetActivityMeasures( + DateTime.Parse("2017-01-01"), + DateTime.Parse("2017-03-30"), + userId, + oauthToken, + oauthSecret + ); + ``` + + Other available methods include `GetSleepSummary`, `GetWorkouts`, `GetBodyMeasures`, etc. Check the `WithingsClient` class for all available methods and their signatures.