【问题标题】:Google Fit API - Get time of exerciseGoogle Fit API - 获取锻炼时间
【发布时间】:2016-12-15 19:52:37
【问题描述】:

我正在尝试使用 Google Fit Api 创建一个应用程序,并且我正在尝试获取用户的总锻炼时间(假设锻炼是步行)。我想要的基本上是获得下图中标记的值:

Google Fit Time Screenshot

我正在考虑使用会话 (https://developers.google.com/fit/android/using-sessions),但如果 Google 已经提供了一些东西,我更愿意跳过这个。我知道如何获取每日步数/卡路里/距离,但我无法找到任何信息来获取每日锻炼时间。

【问题讨论】:

    标签: android google-fit google-fit-sdk


    【解决方案1】:

    让我描述一下我目前的发现,但还有一个问题......

    您可以使用aggregate api 并按活动类型分组。以下是每日分桶的示例:

    POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
    
    {
        "aggregateBy": [
            {
                "dataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments"
            }
        ],
        "endTimeMillis": "1481788800000",
        "startTimeMillis": "1481702400000",
        "bucketByTime": {
            "period": {
                "timeZoneId": "America/Los_Angeles",
                "type": "day",
                "value": 1
            }
        }
    }
    

    该调用将返回许多记录,每个记录包含三个值:活动类型、持续时间(以毫秒为单位)和段数。您可以在以下位置找到活动类型:https://developers.google.com/fit/rest/v1/reference/activity-types。您可以将您感兴趣的活动类型的毫秒数相加。

    现在,问题 - 我看到了 API 和 Fit 应用程序之间活动类型不匹配的示例。我不知道这种不匹配有多普遍。请参阅我的问题:Getting active time from Google Fit Rest API

    【讨论】:

    • 感谢您的回复。我错过了提到我没有使用 REST API 而是用于 android 的 API。无论如何,我都能找到并使用汇总数据。
    猜你喜欢
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多