Praca z sesjami
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Interfejs Fitness API typu REST umożliwia tworzenie i pobieranie sesji. Sesje reprezentują przedział czasowy
podczas których użytkownicy wykonują ćwiczenia.
Sesje są reprezentowane przez zasób Users.session
.
Aktywności są przechowywane w kategorii „ActivityType”.
liczba całkowita.
Wstaw sesję
Ten przykład pokazuje, jak wstawić sesję.
- Metoda HTTP
- UDERZENIE
- Adres URL żądania
https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId
- Treść żądania
{
"id": "someSessionId",
"name": "My example workout",
"description": "A very intense workout",
"startTimeMillis": 1396710000000,
"endTimeMillis": 1396713600000,
"version": 1,
"lastModifiedToken": "exampleToken",
"application": {
"detailsUrl": "http://example.com",
"name": "Foo Example App",
"version": "1.0"
},
"activityType": 1
}
- Odpowiedź
Odpowiedź to kod stanu 200 OK
. Treść odpowiedzi zawiera reprezentację obiektu JSON
.
- Polecenie zwijania
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X PUT \
--header "Content-Type: application/json;encoding=utf-8" -d @createsession.json \
"https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId"
Wyświetl listę istniejących sesji
Ten przykład pokazuje, jak wyświetlić listę istniejących sesji z kwietnia 2014 r.
- Metoda HTTP
- POBIERZ
- Adres URL żądania
https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z
- Treść żądania
- Brak.
- Odpowiedź
- Odpowiedź to kod stanu
200 OK
. Treść odpowiedzi zawiera reprezentacje wszystkich danych w formacie JSON
z istniejących sesji, które pasują do czasu rozpoczęcia i zakończenia podanego w parametrach zapytania.
- Polecenie zwijania
$ curl --header "Authorization: Bearer ya29.1.yourtokenvalue" -X GET \
--header "Content-Type: application/json;encoding=utf-8" \
"https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z"
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-31 UTC.
[null,null,["Ostatnia aktualizacja: 2025-08-31 UTC."],[[["\u003cp\u003eThe Fitness REST API allows you to create and retrieve fitness sessions, which represent periods of user activity.\u003c/p\u003e\n"],["\u003cp\u003eSessions are managed using the \u003ccode\u003eUsers.session\u003c/code\u003e resource and contain data like start/end times, activity type, and optional metadata.\u003c/p\u003e\n"],["\u003cp\u003eYou can insert new sessions using a PUT request to the API with session details in the request body.\u003c/p\u003e\n"],["\u003cp\u003eExisting sessions can be listed by sending a GET request with optional start and end time parameters to filter results.\u003c/p\u003e\n"],["\u003cp\u003eFor best practices on handling user data, refer to the Responsible use of Google Fit guidelines.\u003c/p\u003e\n"]]],[],null,["# Working with Sessions\n\nThe Fitness REST API lets you create and obtain sessions. Sessions represent a time interval\nduring which users perform a fitness activity.\n\nSessions are represented by the [`Users.session`](/fit/rest/v1/reference/users/sessions) resource.\n\nActivities are stored in an ['ActivityType'](/fit/rest/v1/reference/activity-types)\ninteger.\n| **Important:** For best practices when managing user data, see [Responsible use of Google Fit](/fit/overview#responsible_use_of_google_fit).\n\nInsert a session\n----------------\n\nThis example demonstrates how to insert a session.\n\nHTTP method\n: PUT\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/sessions/`**someSessionId**\n\nRequest body\n:\n\n {\n \"id\": \"someSessionId\",\n \"name\": \"My example workout\",\n \"description\": \"A very intense workout\",\n \"startTimeMillis\": 1396710000000,\n \"endTimeMillis\": 1396713600000,\n \"version\": 1,\n \"lastModifiedToken\": \"exampleToken\",\n \"application\": {\n \"detailsUrl\": \"http://example.com\",\n \"name\": \"Foo Example App\",\n \"version\": \"1.0\"\n },\n \"activityType\": 1\n }\n\nResponse\n\n: The response is a `200 OK` status code. The response body contains a JSON representation of the\n session.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.1.yourtokenvalue\" -X PUT \\\n --header \"Content-Type: application/json;encoding=utf-8\" -d @createsession.json \\\n \"https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId\"\n ```\n\nList existing sessions\n----------------------\n\nThis example demonstrates how to list existing sessions from April 2014.\n\nHTTP method\n: GET\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/sessions`**?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z**\n\nRequest body\n: None.\n\nResponse\n: The response is a `200 OK` status code. The response body contains JSON representations of all\n existing sessions that match the start and end times provided in the query parameters.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.1.yourtokenvalue\" -X GET \\\n --header \"Content-Type: application/json;encoding=utf-8\" \\\n \"https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z\"\n ```"]]