Các API của Google Fit, bao gồm cả API Google Fit REST, sẽ ngừng hoạt động vào năm 2026. Kể từ ngày 1 tháng 5 năm 2024, nhà phát triển không thể đăng ký sử dụng các API này.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Mọi yêu cầu mà ứng dụng của bạn gửi đến Fitness API phải bao gồm một mã thông báo uỷ quyền. Mã này cũng giúp Google xác định ứng dụng của bạn.
Giao thức uỷ quyền
Ứng dụng của bạn phải sử dụng OAuth 2.0 để uỷ quyền cho các yêu cầu. Chúng tôi không hỗ trợ giao thức cấp phép nào khác. Nếu ứng dụng của bạn sử dụng tính năng Đăng nhập bằng Google, thì Google sẽ xử lý một số khía cạnh trong quá trình uỷ quyền cho bạn.
Các loại dữ liệu mà ứng dụng của bạn muốn truy cập tương ứng với các phạm vi. Để có thể truy cập vào các loại dữ liệu, bạn cần xác định xem phạm vi tương ứng của các loại dữ liệu đó có nhạy cảm hay bị hạn chế hay không và làm theo các bước liên quan khi đăng ký xác minh.
Hãy xem bước 3 của quy trình cấp quyền cho yêu cầu dưới đây.
Cấp phép cho các yêu cầu bằng OAuth 2.0
Tất cả các yêu cầu đối với Fitness API phải được một người dùng đã xác thực cho phép.
Thông tin chi tiết về quy trình cấp quyền hay "luồng" của OAuth 2.0 sẽ phụ thuộc vào loại ứng dụng mà bạn đang viết. Quy trình chung này áp dụng cho tất cả các loại ứng dụng:
Khi bạn tạo ứng dụng, hãy đăng ký ứng dụng đó bằng Google API Console. Sau đó, Google cung cấp thông tin bạn sẽ cần sau này, chẳng hạn như mã ứng dụng khách và mật khẩu ứng dụng khách.
Kích hoạt API Thể dục trong Bảng điều khiển Google API. (Nếu API không được liệt kê trong Bảng điều khiển API, hãy bỏ qua bước này.)
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\u003cp\u003eAll requests to the Google Fitness API require an OAuth 2.0 authorization token to identify your application and grant access.\u003c/p\u003e\n"],["\u003cp\u003eApplications need to be registered using the Google API Console, activate the Fitness API, and potentially undergo a verification process depending on the requested data types and their sensitivity.\u003c/p\u003e\n"],["\u003cp\u003eAccess to user data is granted through a user consent screen, providing your application with a short-lived access token upon approval.\u003c/p\u003e\n"],["\u003cp\u003eData type access corresponds to specific scopes, necessitating review of scope requirements for your application's desired functionalities.\u003c/p\u003e\n"]]],[],null,["# Authorizing Requests\n\nEvery request your application sends to the Fitness API must include an\nauthorization token. The token also identifies your application to Google.\n\nAuthorization protocol\n----------------------\n\nYour application must use [OAuth\n2.0](https://developers.google.com/identity/protocols/oauth2) to authorize\nrequests. No other authorization protocols are supported. If your application\nuses [Google Sign-In](https://developers.google.com/identity/#google-sign-in),\nsome aspects of authorization are handled for you.\n\nThe [data types](/fit/datatypes) your app wants to access correspond to\n[scopes](/fit/datatypes#authorization_scopes). Before you can access data types,\nyou'll need to identify if their corresponding scopes are [sensitive or\nrestricted](/fit/datatypes#authorization_scopes) and follow the relevant steps\nwhen [applying for verification](/fit/verification).\nSee step 3 of [authorizing requests](#authorizing_requests_with_oauth_20) below.\n\nAuthorizing requests with OAuth 2.0\n-----------------------------------\n\nAll requests to the Fitness API must be authorized by an authenticated user.\n\nThe details of the authorization process, or \"flow,\" for OAuth 2.0 will\ndepend on the kind of app you're writing. This general process applies to all\napp types:\n\n1. When you create your application, register it using the [Google API\n Console](https://console.developers.google.com/). Google then provides information you'll need later, such as a client ID and a client secret.\n2. Activate the Fitness API in the Google API Console. (If the API isn't listed in the API Console, then skip this step.)\n3. [Apply for verification](/fit/verification) and submit the relevant supporting information for why your app needs certain scopes. The [data types](/fit/datatypes) your app needs to access correspond to [scopes your app needs to request](/fit/datatypes#authorization_scopes).\n4. If your app is verified, Google displays a consent screen to the user, asking them to authorize your app to access their data.\n5. If the user approves, then Google gives your application a short-lived access token.\n6. Your application requests user data, attaching the access token to the request.\n7. If Google determines that your request and the token are valid, it returns the requested data.\n\n| **Note:** Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's [OAuth 2.0\n| documentation](https://developers.google.com/identity/protocols/oauth2).\n\nRead about the OAuth scopes for the Fitness API\n[here](https://developers.google.com/identity/protocols/oauth2/scopes#fitness).\nLook up [which scope is needed for each data type](/fit/datatypes)."]]