The Google Health API tracks user steps and activity data using the steps interval data type. Steps count represents a fundamental measure of daily physical activity, helping developers track fitness progress, calculate energy expenditure, and build user-facing daily activity summaries.
نحوه خواندن و ساختاردهی معیارهای شمارش مراحل در برنامه خود را برای ارائه بهترین تجربه به کاربران خود درک کنید.
انواع داده پشتیبانی شده
این API از نوع داده زیر برای ردیابی تعداد گامها پشتیبانی میکند:
نوع دادهdataTypeپارامتر filter | موجود است عملیات | محدوده |
|---|---|---|
مراحلstepssteps نوع رکورد: فاصلهای دستگاههای سازگار
| فهرست کردن، تطبیق دادن، جمع کردن، جمع کردن روزانه | .activity_and_fitness.readonly.activity_and_fitness.writeonly |
بخشهای زیر جزئیات فنی مربوط به نوع دادهی steps ، از جمله مثالهای نمایش REST و دستورالعملهای یکپارچهسازی را ارائه میدهند.
دامنههای مورد نیاز
برای دسترسی به این نوع داده، برنامه شما باید دامنههای OAuth زیر را درخواست کند:
- بخوانید :
https://www.googleapis.com/auth/googlehealth.activity_and_fitness.readonly - بنویسید :
https://www.googleapis.com/auth/googlehealth.activity_and_fitness.writeonly
دستورالعملها
هنگام ادغام ردیابی مراحل در برنامه خود، این دستورالعملهای طراحی و پیادهسازی را دنبال کنید.
مرور روزانه
To aggregate daily step counts accurately under travel, time zone changes, or daylight savings, don't perform client-side duration calculations. Instead, query the dailyRollUp endpoint which reconciles physical data gaps automatically using the UTC offsets. The rollup returns a StepsRollupValue containing the countSum field, representing the total accumulated steps for the requested day.
ترسیم رابطهای کاربری (آشتیسازی)
When building user interface elements to display step data, use the reconcile endpoint. If multiple data sources (such as a smartwatch and a mobile phone) have recorded steps at the same time, the reconcile endpoint resolves conflicts and merges the streams to return a single, reconciled data stream.
ردیابی و هیستوگرامهای درونروزی
برای نمایش فعالیت دقیق کاربر در طول روز (مانند نمودارها و گرافها):
- هیستوگرامهای گام ساعتی: نقطه پایانی
rollUpرا با مشخص کردن مدت زمان (مثلاً3600sبه مدت ۱ ساعت) با استفاده از پارامترwindowSizeجستجو کنید. - تمام رکوردهای مرحله: از نقطه پایانی
listبرای دریافت جزئیترین و خامترین رکوردهای مرحله استفاده کنید.
هر دو نقطه پایانی rollUp و reconcile ، پارامتر پرس و جوی dataSourceFamily را میپذیرند و به شما امکان میدهند دادهها را از گروههای منبع خاص فیلتر کنید.
همگامسازی بلادرنگ با استفاده از وبهوکها
Subscribe to the steps data type collection to get notified in real time when new step data is imported or synchronized. Rather than polling REST endpoints, update client-side dashboards dynamically in response to these webhook notifications. For details on how to set up subscriptions, see Webhook subscriptions .
مدیریت صفرهای واقعی
The Google Health API implements true zeros to resolve sedentary intervals. If a user is wearing a tracker but not walking during a given period, the API returns a record for that interval that contains the normal data source and timestamp metadata but omits the count property.
این به شما امکان میدهد بین موارد زیر تمایز قائل شوید:
- دورههای ثابت روی مچ دست: کاربر دستگاه را پوشیده اما راه نمیرود. این حالت رکوردها را بدون ویژگی
countبرمیگرداند (به عنوان گامهای صفر تفسیر میشود). - دورههای عدم استفاده از مچ دست: کاربر دستگاه را نپوشیده است. این حالت هیچ رکوردی را برنمیگرداند و منجر به شکافهای بزرگ داده میشود.
برای جزئیات بیشتر به راهنمای « حضور دادهها و صفرهای واقعی» مراجعه کنید.