Ejemplo n.º 1
0
        public async Task <Activity> GetDayActivityAsync(string Currentdate, string userId)
        {
            var appCredentials = AppCredentials.ToString();


            var oAuth_params = OAuthUtility.BuildBasicParameters(AppCredentials.ConsumerKey, AppCredentials.ConsumerSecret, "https://wbsapi.withings.net", HttpMethod.Get, this.AccessToken)
                               .Where(p => p.Key != "oauth_signature")
                               .OrderBy(p => p.Key);

            string startdate = ("2017-02-30");
            string date      = ("2017-03-24");

            string requestUri = $"https://wbsapi.withings.net/v2/measure?action=getactivity&userid={userId}&date={date}&";

            requestUri += string.Join("&", oAuth_params.Select(kvp => kvp.Key + "=" + kvp.Value));

            var signature = OAuthUtility.BuildBasicParameters(AppCredentials.ConsumerKey, AppCredentials.ConsumerSecret, requestUri, HttpMethod.Get, this.AccessToken)
                            .First((KeyValuePair <string, string> p) => p.Key == "oauth_signature").Value;

            string json = await HttpClient.GetStringAsync(requestUri + "&oauth_signature=" + signature);

            var o = JObject.Parse(json);


            return(new Activity
            {
                Calories = (float)o["body"]["calories"],
                Date = (string)o["body"]["date"],
                Distance = (float)o["body"]["distance"],
                Elevation = (float)o["body"]["elevation"],
                Intense = (int)o["body"]["intense"],
                Moderate = (int)o["body"]["moderate"],
                Soft = (int)o["body"]["soft"],
                Steps = (int)o["body"]["steps"],
                TimeZone = (string)o["body"]["timezone"],
                TotalCalories = (float)o["body"]["totalcalories"]
            });
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <MeasureGroup> > GetBodyMeasureAsync(string userId, string deviceType)
        {
            var appCredentials = AppCredentials.ToString();


            var oAuth_params = OAuthUtility.BuildBasicParameters(AppCredentials.ConsumerKey, AppCredentials.ConsumerSecret, "https://wbsapi.withings.net", HttpMethod.Get, this.AccessToken)
                               .Where(p => p.Key != "oauth_signature")
                               .OrderBy(p => p.Key);


            string requestUri = $"https://wbsapi.withings.net/measure?action=getmeas&userid={userId}&devtype={deviceType}&";

            requestUri += string.Join("&", oAuth_params.Select(kvp => kvp.Key + "=" + kvp.Value));

            var signature = OAuthUtility.BuildBasicParameters(AppCredentials.ConsumerKey, AppCredentials.ConsumerSecret, requestUri, HttpMethod.Get, this.AccessToken)
                            .First((KeyValuePair <string, string> p) => p.Key == "oauth_signature").Value;

            string json = await HttpClient.GetStringAsync(requestUri + "&oauth_signature=" + signature);

            var o = JObject.Parse(json);

            return(JsonConvert.DeserializeObject <IEnumerable <MeasureGroup> >(o["body"]["measuregrps"].ToString()));
        }