डेटा सोर्स मैनेज करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Fitness REST API से आपको डेटा सोर्स बनाने, पाने, और अपडेट करने की सुविधा मिलती है. डेटा सोर्स से पता चलता है कि
सेंसर डेटा का एक खास सोर्स है. फ़िटनेस डेटा को फ़िटनेस में शामिल करने के लिए, डेटा सोर्स का इस्तेमाल किया जाता है
किसी खास डेटा सोर्स से डाला गया फ़िटनेस डेटा वापस पाया जा सकता है.
डेटा सोर्स Users.dataSources
से दिखाए जाते हैं
संसाधन.
डेटा स्रोत बनाएं
इस उदाहरण में, "MyDataSource" नाम का नया डेटा सोर्स बनाने का तरीका बताया गया है
जिससे कदमों की संख्या में बढ़ोतरी होती है.
- एचटीटीपी तरीका
- पोस्ट करें
- URL का अनुरोध करें
https://www.googleapis.com/fitness/v1/users/me/dataSources
- अनुरोध का मुख्य भाग
{
"dataStreamName": "MyDataSource",
"type": "derived",
"application": {
"detailsUrl": "http://example.com",
"name": "Foo Example App",
"version": "1"
},
"dataType": {
"field": [
{
"name": "steps",
"format": "integer"
}
],
"name": "com.google.step_count.delta"
},
"device": {
"manufacturer": "Example Manufacturer",
"model": "ExampleTablet",
"type": "tablet",
"uid": "1000001",
"version": "1.0"
}
}
- जवाब
अगर डेटा सोर्स बन जाता है, तो रिस्पॉन्स का स्टेटस 200 OK
होता है
कोड. जवाब के मुख्य हिस्से में डेटा सोर्स को JSON फ़ॉर्मैट में दिखाया जाता है,
datasource.dataStreamId
सहित
प्रॉपर्टी डालें, जिसका इस्तेमाल बाद के अनुरोधों के लिए डेटा सोर्स आईडी के तौर पर किया जा सकता है.
- कर्ल निर्देश
$ curl --header "Authorization: Bearer ya29.yourtokenvalue" -X POST \
--header "Content-Type: application/json;encoding=utf-8" -d @createds.json \
"https://www.googleapis.com/fitness/v1/users/me/dataSources"
कोई खास डेटा सोर्स पाना
इस उदाहरण में, डेटा सोर्स ("MyDataSource") को वापस पाने का तरीका बताया गया है
जो आपने पिछले उदाहरण में बनाया था. कोई नया डेटा सोर्स बनाने पर,
dataStreamId
में एक यूनीक आइडेंटिफ़ायर शामिल होता है. इसे "1234567890" के तौर पर दिखाया जाता है
उदाहरण). यह आपके डेवलपर प्रोजेक्ट का नंबर है और यह
उस खास डेवलपर खाते का इस्तेमाल करके किए गए सभी अनुरोध. समस्याओं को हल करने के बारे में ज़्यादा जानने के लिए,
आपके बनाए गए डेटा सोर्स से dataStreamId
.
- एचटीटीपी तरीका
- पाएं
- URL का अनुरोध करें
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource
- अनुरोध का मुख्य भाग
- बिलकुल नहीं
- जवाब
- डेटा सोर्स मौजूद होने पर, रिस्पॉन्स के तौर पर
200 OK
स्टेटस कोड दिखेगा. जवाब के मुख्य हिस्से में
डेटा सोर्स का JSON फ़ॉर्मैट.
- कर्ल निर्देश
$ curl --header "Authorization: Bearer ya29.yourtokenvalue" -X GET
--header "Content-Type: application/json;encoding=utf-8"
"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource"
कुल डेटा पाएं
इस उदाहरण में, एग्रीगेट किए गए डेटा सोर्स के लिए किसी खास डेटा सोर्स से क्वेरी करने का तरीका बताया गया है
इस मामले में estimated_steps
, जो डेटा दिखाने के लिए इस्तेमाल किया जाने वाला डेटा सोर्स है
कदमों की संख्या बढ़ाने के लिए किया जा सकता है. ध्यान दें कि JSON के अनुरोध में टाइमस्टैंप
मुख्य भाग मिलीसेकंड में होते हैं.
- एचटीटीपी तरीका
- पोस्ट करें
- URL का अनुरोध करें
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
- अनुरोध का मुख्य भाग
{
"aggregateBy": [{
"dataSourceId":
"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1454284800000,
"endTimeMillis": 1455062400000
}
- जवाब
अगर डेटा सोर्स मौजूद हैं, तो रिस्पॉन्स 200 OK
स्टेटस कोड होगा. कॉन्टेंट बनाने
रिस्पॉन्स के मुख्य हिस्से में डेटा सोर्स को JSON फ़ॉर्मैट में दिखाया गया है.
- कर्ल निर्देश
$ curl --header "Authorization: Bearer ya29.yourtokenvalue" -X POST \
--header "Content-Type: application/json;encoding=utf-8" -d @aggregate.json \
"https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"
डेटा सोर्स अपडेट करना
इस उदाहरण में, डेटा के लिए नाम और डिवाइस का वर्शन अपडेट करने का तरीका बताया गया है
स्रोत.
- एचटीटीपी तरीका
- पुट
- URL का अनुरोध करें
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource
- अनुरोध का मुख्य भाग
{
"dataStreamId": "derived:com.google.step_count.delta:1234567890:Example Manufacturer:ExampleTablet:1000001:MyDataSource",
"dataStreamName": "MyDataSource",
"type": "derived",
"application": {
"detailsUrl": "http://example.com",
"name": "Foo Example App",
"version": "1"
},
"dataType": {
"field": [
{
"name": "steps",
"format": "integer"
}
],
"name": "com.google.step_count.delta"
},
"device": {
"manufacturer": "Example Manufacturer",
"model": "ExampleTablet",
"type": "tablet",
"uid": "1000001",
"version": "2.0"
}
}
- जवाब
अगर डेटा सोर्स अपडेट हो जाता है, तो रिस्पॉन्स का स्टेटस 200 OK
होगा
कोड. जवाब के मुख्य हिस्से में, डेटा सोर्स को JSON फ़ॉर्मैट में दिखाया जाता है.
- कर्ल निर्देश
$ curl --header "Authorization: Bearer ya29.yourtokenvalue" -X PUT \
--header "Content-Type: application/json;encoding=utf-8" -d @updateds.json \
"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource"
डेटा सोर्स मिटाना
इस उदाहरण में डेटा सोर्स को मिटाने का तरीका बताया गया है.
- एचटीटीपी तरीका
- मिटाएं
- URL का अनुरोध करें
https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource
- अनुरोध का मुख्य भाग
- बिलकुल नहीं
- जवाब
- अगर डेटा सोर्स मिटा दिया जाता है, तो रिस्पॉन्स के तौर पर
200 OK
की स्थिति दिखेगी
कोड. जवाब के मुख्य हिस्से में, उस डेटा सोर्स को JSON फ़ॉर्मैट में दिखाया जाता है जो
मिटा दिया गया था.
- कर्ल निर्देश
$ curl --header "Authorization: Bearer ya29.yourtokenvalue" -X DELETE \
--header "Content-Type: application/json;encoding=utf-8" \
"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource"
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eThe Fitness REST API allows you to manage data sources, which represent unique sources of sensor data for inserting and retrieving fitness data within the Fitness Store.\u003c/p\u003e\n"],["\u003cp\u003eYou can create, retrieve, update, and delete data sources using the API with specific HTTP methods and request URLs.\u003c/p\u003e\n"],["\u003cp\u003eData sources can be identified using a unique \u003ccode\u003edataStreamId\u003c/code\u003e, including your developer project number, for subsequent interactions.\u003c/p\u003e\n"],["\u003cp\u003eThe API supports aggregating data from specific data sources within defined time ranges, like retrieving daily step counts.\u003c/p\u003e\n"],["\u003cp\u003eData source management should follow responsible data handling practices as outlined in the Google Fit guidelines for user privacy and security.\u003c/p\u003e\n"]]],[],null,["# Managing Data Sources\n\nThe Fitness REST API lets you create, obtain, and update data sources. A data source represents\na unique source of sensor data. You use data sources to insert fitness data into the fitness\nstore, and you can retrieve fitness data inserted by a particular data source.\n\nData sources are represented by the [`Users.dataSources`](/fit/rest/v1/reference/users/dataSources)\nresource.\n| **Important:** For best practices when managing user data, see [Responsible use of Google Fit](/fit/overview#responsible_use_of_google_fit).\n\nCreate a data source\n--------------------\n\nThis example demonstrates how to create a new data source named \"MyDataSource\"\nthat provides step count increments.\n\nHTTP method\n: POST\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/dataSources`\n\nRequest body\n:\n\n {\n \"dataStreamName\": \"MyDataSource\",\n \"type\": \"derived\",\n \"application\": {\n \"detailsUrl\": \"http://example.com\",\n \"name\": \"Foo Example App\",\n \"version\": \"1\"\n },\n \"dataType\": {\n \"field\": [\n {\n \"name\": \"steps\",\n \"format\": \"integer\"\n }\n ],\n \"name\": \"com.google.step_count.delta\"\n },\n \"device\": {\n \"manufacturer\": \"Example Manufacturer\",\n \"model\": \"ExampleTablet\",\n \"type\": \"tablet\",\n \"uid\": \"1000001\",\n \"version\": \"1.0\"\n }\n }\n\nResponse\n\n: If the data source is created successfully, the response is a `200 OK` status\n code. The response body contains a JSON representation of the data source,\n including a [`datasource.dataStreamId`](/fit/rest/v1/reference/users/dataSources#dataStreamId)\n property that you can use as the data source ID for subsequent requests.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" -X POST \\\n --header \"Content-Type: application/json;encoding=utf-8\" -d @createds.json \\\n \"https://www.googleapis.com/fitness/v1/users/me/dataSources\"\n ```\n\nGet a particular data source\n----------------------------\n\nThis example demonstrates how to retrieve the data source (\"MyDataSource\")\nthat you created in the previous example. When you create a new data source,\nthe `dataStreamId` includes a unique identifier (shown as \"1234567890\" in these\nexamples). This is your developer project number, and it will be the same for\nall requests made using that particular developer account. Be sure to use the\n`dataStreamId` from the data source you created.\n\nHTTP method\n: GET\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/dataSources/`**derived:com.google.step_count.delta:\u003cvar class=\"apiparam\" translate=\"no\"\u003e1234567890\u003c/var\u003e:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource**\n\nRequest body\n: None\n\nResponse\n: If the data source exists, the response is a `200 OK` status code. The response body contains a\n JSON representation of the data source.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" -X GET \n\n --header \"Content-Type: application/json;encoding=utf-8\" \n\n \"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource\"\n ```\n\nGet aggregated data\n-------------------\n\nThis example demonstrates how to query a specific data source for aggregated\ndata, in this case `estimated_steps`, which is the data source used to show\nstep count in the Google Fit app. Note that timestamps in the JSON request\nbody are in milliseconds.\n\nHTTP method\n: POST\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate`\n\nRequest body\n:\n\n {\n \"aggregateBy\": [{\n \"dataSourceId\":\n \"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps\"\n }],\n \"bucketByTime\": { \"durationMillis\": 86400000 },\n \"startTimeMillis\": 1454284800000,\n \"endTimeMillis\": 1455062400000\n }\n\nResponse\n\n: If the data source(s) exist, the response is a `200 OK` status code. The\n response body contains a JSON representation of the data source.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" -X POST \\\n --header \"Content-Type: application/json;encoding=utf-8\" -d @aggregate.json \\\n \"https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate\"\n ```\n\nUpdate a data source\n--------------------\n\nThis example demonstrates how to update the name and device version for a data\nsource.\n\nHTTP method\n: PUT\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/dataSources/`**derived:com.google.step_count.delta:\u003cvar class=\"apiparam\" translate=\"no\"\u003e1234567890\u003c/var\u003e:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource**\n\nRequest body\n:\n\n {\n \"dataStreamId\": \"derived:com.google.step_count.delta:1234567890:Example Manufacturer:ExampleTablet:1000001:MyDataSource\",\n \"dataStreamName\": \"MyDataSource\",\n \"type\": \"derived\",\n \"application\": {\n \"detailsUrl\": \"http://example.com\",\n \"name\": \"Foo Example App\",\n \"version\": \"1\"\n },\n \"dataType\": {\n \"field\": [\n {\n \"name\": \"steps\",\n \"format\": \"integer\"\n }\n ],\n \"name\": \"com.google.step_count.delta\"\n },\n \"device\": {\n \"manufacturer\": \"Example Manufacturer\",\n \"model\": \"ExampleTablet\",\n \"type\": \"tablet\",\n \"uid\": \"1000001\",\n \"version\": \"2.0\"\n }\n }\n\nResponse\n\n: If the data source is updated successfully, the response is a `200 OK` status\n code. The response body contains a JSON representation of the data source.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" -X PUT \\\n --header \"Content-Type: application/json;encoding=utf-8\" -d @updateds.json \\\n \"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource\"\n ```\n\nDelete a data source\n--------------------\n\nThis example demonstrates how to delete a data source.\n\nHTTP method\n: DELETE\n\nRequest URL\n: `https://www.googleapis.com/fitness/v1/users/me/dataSources/`**derived:com.google.step_count.delta:\u003cvar class=\"apiparam\" translate=\"no\"\u003e1234567890\u003c/var\u003e:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource**\n\nRequest body\n: None\n\nResponse\n: If the data source is deleted successfully, the response is a `200 OK` status\n code. The response body contains a JSON representation of the data source that\n was deleted.\n\nCurl command\n:\n\n ```\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" -X DELETE \\\n --header \"Content-Type: application/json;encoding=utf-8\" \\\n \"https://www.googleapis.com/fitness/v1/users/me/dataSources/derived:com.google.step_count.delta:1234567890:Example%20Manufacturer:ExampleTablet:1000001:MyDataSource\"\n ```"]]