การทำงานกับเซสชัน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Fitness REST API ให้คุณสร้างและรับเซสชัน เซสชันจะแสดงช่วงเวลา
ระหว่างที่ผู้ใช้ทำกิจกรรมการออกกำลังกาย
เซสชันจะแสดงด้วยทรัพยากร Users.session
กิจกรรมจะจัดเก็บใน "ActivityType"
จำนวนเต็ม
แทรกเซสชัน
ตัวอย่างนี้แสดงวิธีแทรกเซสชัน
- เมธอด HTTP
- วาง
- URL คำขอ
https://www.googleapis.com/fitness/v1/users/me/sessions/someSessionId
- เนื้อหาของคำขอ
{
"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
}
- คำตอบ
การตอบกลับจะเป็นรหัสสถานะ 200 OK
เนื้อหาการตอบกลับมีการแสดงไฟล์ JSON ของ
เซสชัน
- คำสั่ง Curl
$ 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"
แสดงรายการเซสชันที่มีอยู่
ตัวอย่างนี้แสดงวิธีแสดงรายการเซสชันที่มีอยู่ตั้งแต่เดือนเมษายน 2014
- เมธอด HTTP
- รับ
- URL คำขอ
https://www.googleapis.com/fitness/v1/users/me/sessions?startTime=2014-04-01T00:00:00.000Z&endTime=2014-04-30T23:59:59.999Z
- เนื้อหาของคำขอ
- ไม่มี
- คำตอบ
- การตอบกลับจะเป็นรหัสสถานะ
200 OK
เนื้อหาการตอบกลับมีการแสดงแทน JSON ทั้งหมด
เซสชันที่มีอยู่ซึ่งตรงกับเวลาเริ่มต้นและสิ้นสุดที่ระบุไว้ในพารามิเตอร์การค้นหา
- คำสั่ง Curl
$ 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"
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 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 ```"]]