피트니스 REST API를 사용하면 데이터 소스를 만들고, 가져오고, 업데이트할 수 있습니다. 데이터 소스는 센서 데이터의 고유한 소스를 나타냅니다. 데이터 소스를 사용하여 피트니스 저장소에 피트니스 데이터를 삽입하고 특정 데이터 소스에서 삽입한 피트니스 데이터를 검색할 수 있습니다.
데이터 소스는 Users.dataSources
리소스로 표시됩니다.
데이터 소스 만들기
이 예에서는 단계 수 증가를 제공하는 "MyDataSource"라는 새 데이터 소스를 만드는 방법을 보여줍니다.
- HTTP 메서드
- 게시
- 요청 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
상태 코드가 반환됩니다. 응답 본문에는 후속 요청의 데이터 소스 ID로 사용할 수 있는datasource.dataStreamId
속성이 포함된 데이터 소스의 JSON 표현이 포함됩니다.- curl 명령어
$ 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
를 사용해야 합니다.
- HTTP 메서드
- 받기
- 요청 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 명령어
$ 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
)를 쿼리하는 방법을 보여줍니다. 이 경우에는 Google 피트니스 앱의 걸음 수를 표시하는 데 사용되는 데이터 소스입니다. JSON 요청 본문의 타임스탬프는 밀리초 단위입니다.
- HTTP 메서드
- 게시
- 요청 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 명령어
$ 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"
데이터 소스 업데이트
이 예에서는 데이터 소스의 이름과 기기 버전을 업데이트하는 방법을 보여줍니다.
- HTTP 메서드
- 처리
- 요청 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 명령어
$ 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"
데이터 소스 소거
이 예시에서는 데이터 소스를 삭제하는 방법을 보여줍니다.
- HTTP 메서드
- 삭제
- 요청 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 명령어
$ 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"