curl 명령으로 fitbit API를 두드려보십시오
소개
curl 명령을 사용하여 Fitbit API를 두드려 보았으므로 잊지 않도록 메모하십시오.
Fitbit 개발자 사이트 에서 access_token을 가져옵니다. 아래 그림의 빨간색 프레임 부분입니다.
프로필 가져오기
$ curl -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/user/-/profile.json
응답을 쉽게 볼 수 있도록 jq를 설치하는 것이 좋습니다.
$ brew install jq
걸음 수 취득
오늘부터 1개월 전까지의 걸음수를 취득합니다.
$ curl -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json | jq
{
"activities-steps": [
{
"dateTime": "2020-01-22",
"value": "6357"
},
{
"dateTime": "2020-01-23",
"value": "6405"
},
...
{
"dateTime": "2020-02-21",
"value": "2270"
}
]
}
식사 기록
식사를 기록하려면 Fitbit 식품 데이터베이스에서 foodId를 가져와야 합니다.
테스트에서는 "타피오카"를 검색 단어로하고 있습니다.
검색 워드는 인코딩하여 POST해 주지 않으면 오류가 발생합니다.
인코딩 방법은 구그하면 여러 사이트가 나옵니다.
curl -X POST -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/foods/search.json?query=%E3%82%BF%E3%83%94%E3%82%AA%E3%82%AB
query 다음은 검색 단어입니다.
{
"foods": [
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 212,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297945,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフルーツ",
"units": [
304
]
},
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 300,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297918,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカアイス",
"units": [
304
]
},
...
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 275,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 21863417,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフロート ココア(ファーストキッチン)",
"units": [
304
]
}
]
}
가득합니다! 적당한 foodId를 주워 봅시다.
여기에서는 "21863417"을 사용합니다.
그럼 식사를 등록합니다.
curl -X POST \
-H "Authorization: Bearer [your token]" \
--data "foodId=21863417&date=2020-02-21&amount=2&unitId=304&mealTypeId=7&favorite=false" \
https://api.fitbit.com/1/user/-/foods/log.json
제대로 타피오카 플로트 코코아 (...가 등록되었습니다!
참고
Fitbit API
curl 명령 사용법
이번은 여기까지입니다.
Reference
이 문제에 관하여(curl 명령으로 fitbit API를 두드려보십시오), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/morichu78/items/a9fcf8112f0bf56aa708
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ curl -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/user/-/profile.json
응답을 쉽게 볼 수 있도록 jq를 설치하는 것이 좋습니다.
$ brew install jq
걸음 수 취득
오늘부터 1개월 전까지의 걸음수를 취득합니다.
$ curl -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json | jq
{
"activities-steps": [
{
"dateTime": "2020-01-22",
"value": "6357"
},
{
"dateTime": "2020-01-23",
"value": "6405"
},
...
{
"dateTime": "2020-02-21",
"value": "2270"
}
]
}
식사 기록
식사를 기록하려면 Fitbit 식품 데이터베이스에서 foodId를 가져와야 합니다.
테스트에서는 "타피오카"를 검색 단어로하고 있습니다.
검색 워드는 인코딩하여 POST해 주지 않으면 오류가 발생합니다.
인코딩 방법은 구그하면 여러 사이트가 나옵니다.
curl -X POST -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/foods/search.json?query=%E3%82%BF%E3%83%94%E3%82%AA%E3%82%AB
query 다음은 검색 단어입니다.
{
"foods": [
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 212,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297945,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフルーツ",
"units": [
304
]
},
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 300,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297918,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカアイス",
"units": [
304
]
},
...
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 275,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 21863417,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフロート ココア(ファーストキッチン)",
"units": [
304
]
}
]
}
가득합니다! 적당한 foodId를 주워 봅시다.
여기에서는 "21863417"을 사용합니다.
그럼 식사를 등록합니다.
curl -X POST \
-H "Authorization: Bearer [your token]" \
--data "foodId=21863417&date=2020-02-21&amount=2&unitId=304&mealTypeId=7&favorite=false" \
https://api.fitbit.com/1/user/-/foods/log.json
제대로 타피오카 플로트 코코아 (...가 등록되었습니다!
참고
Fitbit API
curl 명령 사용법
이번은 여기까지입니다.
Reference
이 문제에 관하여(curl 명령으로 fitbit API를 두드려보십시오), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/morichu78/items/a9fcf8112f0bf56aa708
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ curl -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/user/-/activities/steps/date/today/1m.json | jq
{
"activities-steps": [
{
"dateTime": "2020-01-22",
"value": "6357"
},
{
"dateTime": "2020-01-23",
"value": "6405"
},
...
{
"dateTime": "2020-02-21",
"value": "2270"
}
]
}
식사를 기록하려면 Fitbit 식품 데이터베이스에서 foodId를 가져와야 합니다.
테스트에서는 "타피오카"를 검색 단어로하고 있습니다.
검색 워드는 인코딩하여 POST해 주지 않으면 오류가 발생합니다.
인코딩 방법은 구그하면 여러 사이트가 나옵니다.
curl -X POST -H "Authorization: Bearer [your token]" https://api.fitbit.com/1/foods/search.json?query=%E3%82%BF%E3%83%94%E3%82%AA%E3%82%AB
query 다음은 검색 단어입니다.
{
"foods": [
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 212,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297945,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフルーツ",
"units": [
304
]
},
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 300,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 19297918,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカアイス",
"units": [
304
]
},
...
{
"accessLevel": "PUBLIC",
"brand": "",
"calories": 275,
"defaultServingSize": 1,
"defaultUnit": {
"id": 304,
"name": "食分",
"plural": "食分"
},
"foodId": 21863417,
"isGeneric": false,
"locale": "ja_JP",
"name": "タピオカフロート ココア(ファーストキッチン)",
"units": [
304
]
}
]
}
가득합니다! 적당한 foodId를 주워 봅시다.
여기에서는 "21863417"을 사용합니다.
그럼 식사를 등록합니다.
curl -X POST \
-H "Authorization: Bearer [your token]" \
--data "foodId=21863417&date=2020-02-21&amount=2&unitId=304&mealTypeId=7&favorite=false" \
https://api.fitbit.com/1/user/-/foods/log.json
제대로 타피오카 플로트 코코아 (...가 등록되었습니다!
참고
Fitbit API
curl 명령 사용법
이번은 여기까지입니다.
Reference
이 문제에 관하여(curl 명령으로 fitbit API를 두드려보십시오), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/morichu78/items/a9fcf8112f0bf56aa708텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)