You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Google Fit睡眠数据读取API返回400 Bad Request错误求助

Fixing 400 Bad Request for Google Fitness API Sleep Sessions Request

Let’s break down why you’re hitting that 400 Bad Request error and fix it step by step:

1. Incorrect Timestamp Format (Most Likely Culprit)

Your startTime parameter has a formatting mistake: 2019-12-05T00:00.000Z is missing a colon between the minutes and seconds. The Google Fitness API strictly follows RFC 3339 timestamp standards, which require the structure YYYY-MM-DDTHH:mm:ss.sssZ.

Corrected startTime: 2019-12-05T00:00:00.000Z

2. Verify Your Scope and Access Token

While https://www.googleapis.com/auth/fitness.activity.read does cover sleep activity (since activityType=72 maps to sleep), double-check two things:

  • You explicitly requested this scope during the OAuth authorization flow (including in Google Playground).
  • Your access token is valid and includes this scope. You can decode the token (it’s a JWT) to confirm the scopes are present in the scope claim.

3. Corrected Request Example

Here’s the fixed version of your HTTP request with proper formatting:

GET /fitness/v1/users/me/sessions?startTime=2019-12-05T00:00:00.000Z&endTime=2019-12-17T23:59:59.999Z&activityType=72 HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer YOUR_ACTUAL_ACCESS_TOKEN
Content-Length: 0

Just replace YOUR_ACTUAL_ACCESS_TOKEN with your valid token, and ensure there are no typos in parameter names or values.

4. Quick Additional Checks

  • Confirm the Fitness API is enabled in your Google Cloud project (you can check this in the Cloud Console under APIs & Services > Enabled APIs & Services).
  • If using Google Playground, make sure you’ve completed the full OAuth flow, including granting the app permission to access your fitness data.

内容的提问来源于stack exchange,提问作者Payal Pandey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 08:07:56