使用gapi开发Google Fit REST API服务时,Discovery Document List API返回URL触发404错误的原因解析
Great catch on figuring out the working URL—let’s break down why your initial attempt failed:
The Two Discovery Document URL Formats
Google offers two ways to fetch API discovery documents, but not all services support both anymore:
- Service-specific endpoint (deprecated for many services): The URL you got from the Discovery List API (
https://fitness.googleapis.com/$discovery/rest?version=v1) uses an older, service-specific pattern. This format was common in earlier Google API versions, but many services (including Google Fit) have since phased out support for these endpoints, leading to the 404 error you saw. - Centralized discovery endpoint (current recommended): The working URL you found (
https://www.googleapis.com/discovery/v1/apis/fitness/v1/rest) uses Google's unified, centralized discovery service. This is the modern, supported way to retrieve discovery docs for all Google APIs—it’s more stable, consistently maintained, and the format you’ll find in most up-to-date official documentation.
Why the Discovery List API Returned the Outdated URL
It’s likely a case of metadata lag. The Discovery List API’s database might still retain records of the old service-specific endpoints even though the actual service servers no longer support them. Google sometimes deprecates old endpoints but takes time to update all related metadata sources.
Recommendation
Going forward, prioritize using the centralized discovery endpoint format. You can also directly copy the correct discovery document URL from the official documentation for the specific Google API you’re working with—this ensures you’re always using a valid, supported endpoint.
内容的提问来源于stack exchange,提问作者ogihara

