跳转至

运动卡路里计算

最后更新:2022年03月31日

接口能力

本接口可根据心率、步频及基础体征信息精确计算跑步过程中的卡路里消耗速度。

说明

本接口目前仅适用于跑步场景,其他场景下使用可能造成准确率降低。

请求方法

HTTP方法: POST
请求URL:http://api.amsu-new.com/amsu-analysis/v2/calorie/running/results/
数据提交方式:application/json

Header参数:

字段 类型 描述
Authorization Bearer Token 构造方式为Bearer+(空格)+(Access Token)

Body参数:

字段 类型 必传 范围 描述
hr Integer 40 - 220 心率
cadence Integer 0 - 230 步频
height Integer 90 - 240 身高,单位:cm
weight Float 30.0 - 200.9 体重,单位:kg
age Integer 18 - 120 年龄
gender Integer 0 - 1 性别,男10
waistline Integer 45 - 120 腰围,单位:cm
body_fat Float 3 - 50 体脂率,单位:%(例如体脂率15.1%,则上传15.1

返回参数

字段 类型 描述
burning_rate Float 卡路里燃烧速度,单位: 千卡/分钟

正确返回示例:

HTTP状态码:200

{
    "burning_rate": 8.34
}
错误返回示例:

HTTP状态码不为200

{
    "error": {
        "code": "COMMON.INVALID_FILE_TYPE",
        "msg": "Unsupported file type for field 'ecg_file'."
    }
}

错误码

参见 公共错误码

示例代码

OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"hr\":150,\"cadence\":120,\"height\":168,\"weight\":74,\"age\":37,\"gender\":1,\"waistline\":83,\"body_fat\":20.9}");
Request request = new Request.Builder()
  .url("http://api.amsu-new.com/amsu-analysis/v2/calorie/running/results/")
  .method("POST", body)
  .addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcHBfa2V5OjkzZWUyMGNiNTliOTY0OWY3YzIwIiwiZXhwIjoxNjQ4NTQxODExfQ.UhCfS7doPt7oN9BQaSL5w_GMhB9Jz6D4eYJhBGMDK6k")
  .addHeader("Content-Type", "application/json")
  .build();
Response response = client.newCall(request).execute();
#import <Foundation/Foundation.h>

dispatch_semaphore_t sema = dispatch_semaphore_create(0);

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://api.amsu-new.com/amsu-analysis/v2/calorie/running/results/"]
  cachePolicy:NSURLRequestUseProtocolCachePolicy
  timeoutInterval:10.0];
NSDictionary *headers = @{
  @"Authorization": @"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcHBfa2V5OjkzZWUyMGNiNTliOTY0OWY3YzIwIiwiZXhwIjoxNjQ4NTQxODExfQ.UhCfS7doPt7oN9BQaSL5w_GMhB9Jz6D4eYJhBGMDK6k",
  @"Content-Type": @"application/json"
};

[request setAllHTTPHeaderFields:headers];
NSData *postData = [[NSData alloc] initWithData:[@"{\"hr\":150,\"cadence\":120,\"height\":168,\"weight\":74,\"age\":37,\"gender\":1,\"waistline\":83,\"body_fat\":20.9}" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];

[request setHTTPMethod:@"POST"];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  if (error) {
    NSLog(@"%@", error);
    dispatch_semaphore_signal(sema);
  } else {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
    NSError *parseError = nil;
    NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
    NSLog(@"%@",responseDictionary);
    dispatch_semaphore_signal(sema);
  }
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcHBfa2V5OjkzZWUyMGNiNTliOTY0OWY3YzIwIiwiZXhwIjoxNjQ4NTQxODExfQ.UhCfS7doPt7oN9BQaSL5w_GMhB9Jz6D4eYJhBGMDK6k");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "hr": 150,
  "cadence": 120,
  "height": 168,
  "weight": 74,
  "age": 37,
  "gender": 1,
  "waistline": 83,
  "body_fat": 20.9
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("http://api.amsu-new.com/amsu-analysis/v2/calorie/running/results/", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
import requests
import json

url = "http://api.amsu-new.com/amsu-analysis/v2/calorie/running/results/"

payload = json.dumps({
  "hr": 150,
  "cadence": 120,
  "height": 168,
  "weight": 74,
  "age": 37,
  "gender": 1,
  "waistline": 83,
  "body_fat": 20.9
})
headers = {
  'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhcHBfa2V5OjkzZWUyMGNiNTliOTY0OWY3YzIwIiwiZXhwIjoxNjQ4NTQxODExfQ.UhCfS7doPt7oN9BQaSL5w_GMhB9Jz6D4eYJhBGMDK6k',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)