{"id":32480447,"url":"https://github.com/teramonagi/fitbitr","last_synced_at":"2025-10-27T01:59:01.445Z","repository":{"id":55087770,"uuid":"55100547","full_name":"teramonagi/fitbitr","owner":"teramonagi","description":"Interact with Fitbit data in R using Fitbit API","archived":false,"fork":false,"pushed_at":"2022-09-15T00:31:07.000Z","size":313,"stargazers_count":51,"open_issues_count":11,"forks_count":35,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-10-13T17:55:33.807Z","etag":null,"topics":["fitbit-api","fitbit-data","r","r-package"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teramonagi.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-30T21:55:01.000Z","updated_at":"2025-07-26T17:20:06.000Z","dependencies_parsed_at":"2023-01-18T08:15:45.485Z","dependency_job_id":null,"html_url":"https://github.com/teramonagi/fitbitr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/teramonagi/fitbitr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teramonagi%2Ffitbitr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teramonagi%2Ffitbitr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teramonagi%2Ffitbitr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teramonagi%2Ffitbitr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teramonagi","download_url":"https://codeload.github.com/teramonagi/fitbitr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teramonagi%2Ffitbitr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281202129,"owners_count":26460564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fitbit-api","fitbit-data","r","r-package"],"created_at":"2025-10-27T01:58:52.230Z","updated_at":"2025-10-27T01:59:01.436Z","avatar_url":"https://github.com/teramonagi.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  fig.width=8,\n  fig.height=4,\n  cache=TRUE\n)\n```\n\n# fitbitr \n\n![](https://travis-ci.org/teramonagi/fitbitr.svg?branch=master)\n[![CRAN Version](http://www.r-pkg.org/badges/version/fitbitr)](http://cran.rstudio.com/web/packages/fitbitr) \n![](http://cranlogs.r-pkg.org/badges/grand-total/fitbitr)\n\n`fitbitr` package allows users to interact with Fitbit data in R using Fitbit API.\n\nThis package allows for most of the read and write methods that you might want to use. \n\n## Installation\nfitbitr isn't available from CRAN yet, but you can get it from github with:\n```{r, eval=FALSE}\n# install.packages(\"devtools\")\ndevtools::install_github(\"teramonagi/fitbitr\")\n```\n\n## Preparation  \n### API key\nTo get your own token (API key), you have to register your own application in [here](https://dev.fitbit.com/apps/new).\nFor your reference, we share our setting:\n\n\u003cdiv style=\"width:300px;\"\u003e\n![](man/figures/register_app.png)\n\u003c/div\u003e\n\nAfter registration, you can get your own `FITBIT_KEY` and `FITBIT_SECRET` (referred to as **OAuth 2.0 Client ID** and **Client Secret** in the next figure).\n\n\u003cdiv style=\"width: 50%;\"\u003e\n![](man/figures/manage_my_apps.png)\n\u003c/div\u003e\n\nIf you set the following variables as a global variable, this package will use these values for API key.\n```{r, eval=FALSE}\n# As a global variable\nFITBIT_KEY    \u003c- \"\u003cyour-fitbit-key\u003e\"\nFITBIT_SECRET \u003c- \"\u003cyour-firbit-secret\u003e\"\n# If you want, Default: \"http://localhost:1410/\"\n# FITBIT_CALLBACK \u003c- \"\u003cyour-fitbit-callback\u003e\" \n```\n\nOr, you can set these values as a environment variable\n```{r, eval=FALSE}\nSys.setenv(FITBIT_KEY = \"\u003cyour-fitbit-key\u003e\", FITBIT_SECRET = \"\u003cyour-firbit-secret\u003e\")\n```\n\n### Load libraries\n```{r}\nlibrary(\"fitbitr\")\nlibrary(\"ggplot2\") # for visualization in this document\n```\n\n### Get Fitbit API token\nYou can get your Fitbit toekn using `fitbitr::oauth_token()`:\n```{r, eval=FALSE}\n# Get token\ntoken \u003c- fitbitr::oauth_token()\n# Get token\ntoken \u003c- fitbitr::oauth_token(language=\"en_US\")\n\n# Get token\ntoken \u003c- fitbitr::oauth_token(language=\"en_GB\")\n```\nThis function open a web browser autmatically and return Fitbit token.\n\n```{r, echo=FALSE, cache=FALSE}\n#Adhoc to build this document on my PC...\n#saveRDS(token, \"temp_token\")\ntoken \u003c- readRDS(\"temp_token\")\n```\n\n## How to use\n### Activity\n```{r}\n# Example date\ndate \u003c- \"2017-12-29\"\n\n# Get daily activity summary\nstr(get_activity_summary(token, date))\n\n# Get Activity Time Series\nget_activity_time_series(token, \"distance\", date=date, period=\"7d\")\n\n# Get activity intraday time series\n# You have to use a **personal** key and secret.\ndf \u003c- get_activity_intraday_time_series(token, \"steps\", date, detail_level=\"15min\")\ndf$time \u003c- as.POSIXct(strptime(paste0(df$dateTime, \" \", df$dataset_time), \"%Y-%m-%d %H:%M:%S\"))\nggplot2::ggplot(df, aes(x=time, y=dataset_value)) + geom_line()\n\n# Get Activity Types (complicated nested list)\nlength(get_activity_types(token))\n\n# Get Activity Type (Yoga=52001)\nget_activity_type(token, 52001)\n\n# Get Frequent Activities\nget_frequent_activities(token)\n\n# Get Recent Activities\nget_recent_activity_types(token)\n\n# Add, get and delete favorite activities\nadd_favorite_activity(token, 52001)\nget_favorite_activities(token)\ndelete_favorite_activity(token, 52001)\nget_favorite_activities(token)\n\nget_activity_goals(token, period=\"daily\")\nupdate_activity_goals(token, period=\"daily\", distance=11.3)\nget_activity_goals(token, period=\"daily\")\nget_activity_goals(token, period=\"weekly\")\nupdate_activity_goals(token, period=\"weekly\", steps=\"100000\")\nget_activity_goals(token, period=\"weekly\")\n\n# Get Lifetime Stats\nget_lifetime_stats(token)\n```\n\nYou can find more details in [here](https://dev.fitbit.com/docs/activity/)\n\n### Heart Rate\n```{r}\n# Set a date for example\ndate \u003c- \"2017-12-25\"\n# Get heart rate time series\ndf \u003c- get_heart_rate_time_series(token, date=date, period=\"7d\")\nggplot(df, aes(x=date, y=peak_max)) + geom_line()\n# Get intraday heart rate time series\ndf \u003c- get_heart_rate_intraday_time_series(token, date=date, detail_level=\"15min\")\ndf$time \u003c- as.POSIXct(paste0(date, \" \", df$time))\nggplot(df, aes(x=time, y=value)) + geom_line()\n```\n\nYou can find more details [here](https://dev.fitbit.com/docs/heart-rate/).\n\n### Sleep\n```{r}\n# Get Sleep Logs(date is character or Date)\nx \u003c- get_sleep_logs(token, \"2016-03-30\")\nprint(head(x$sleep))\nx$summary\n\n#Get the current sleep goal.\nget_sleep_goal(token)\n#Update sleep goal\nupdate_sleep_goal(token, 380)\n\n#Get Sleep Time Series\nget_sleep_time_series(token, \"timeInBed\", date=\"2016-04-02\", period=\"7d\")\nget_sleep_time_series(token, \"efficiency\", base_date=\"2016-03-30\", end_date=\"2016-03-30\")\n\n#Log sleep\nlog \u003c- log_sleep(token, \"22:00\", 180, date=\"2010-04-18\")\nprint(head(log))\n\n#Delete sleep log\ndelete_sleep_log(token, log$logId)\n```\n\nYou can find more details [here](https://dev.fitbit.com/docs/sleep/).\n\n### Devices \n```{r}\n# Get deice information you registerd\nget_devices(token)\n```\n\n```{r}\n# Add alarms\ntracker_id \u003c- get_devices(token)$id[1]\nadd_alarm(token, tracker_id, \"07:15-08:00\", \"MONDAY\")\nalarm \u003c- get_alarms(token, tracker_id)\nalarm\n```\n\n```{r}\n# Update the content alarm\nalarm_id \u003c- tail(alarm, 1)$alarmId\nupdate_alarm(token, tracker_id, alarm_id, \"02:15-03:00\", \"FRIDAY\")\nget_alarms(token, tracker_id)\n```\n\n```{r}\n# Delete alarm you registered here\ndelete_alarm(token, tracker_id, alarm_id)\nget_alarms(token, tracker_id)\n```\n\nYou can find more details [here](https://dev.fitbit.com/docs/devices/).\n\n## Contributing\n- Fork it ( https://github.com/teramonagi/fitbitr/fork )\n- Create your feature branch (git checkout -b my-new-feature)\n- Commit your changes (git commit -am 'Add some feature')\n- Push to the branch (git push origin my-new-feature)\n- Create a new Pull Request\n\n## Acknowledgements\n\nMany thanks to Mr.dichika since This package is based on the extension of [myFitbit package](https://github.com/dichika/myFitbit).\n\n\u003c!--\nFuture implementation\n### Food Logging\nYou can find more details [here](https://dev.fitbit.com/docs/food-logging/).\n### Friends\nYou can find more details [here](https://dev.fitbit.com/docs/friends/).\n\n### Subscriptions\n- https://dev.fitbit.com/docs/subscriptions/\n\n### User\n- https://dev.fitbit.com/docs/user/\n### Body \u0026 Weight\nYou can find more details in [here](https://dev.fitbit.com/docs/body/)\n\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteramonagi%2Ffitbitr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteramonagi%2Ffitbitr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteramonagi%2Ffitbitr/lists"}