fitbitScraper/0000755000176200001440000000000013073773730013065 5ustar liggesusersfitbitScraper/inst/0000755000176200001440000000000013073713356014040 5ustar liggesusersfitbitScraper/inst/doc/0000755000176200001440000000000013073713356014605 5ustar liggesusersfitbitScraper/inst/doc/fitbitScraper-examples.R0000644000176200001440000000563413073713356021355 0ustar liggesusers## ------------------------------------------------------------------------ library("fitbitScraper") cookie <- login(email="corynissen@gmail.com", password=Sys.getenv("FBPW")) ## ---- fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'---- dates <- seq(as.Date("2016-04-03"), as.Date("2016-04-09"), by="day") df_list <- lapply(dates, function(x) get_intraday_data(cookie=cookie, what="steps", as.character(x))) df <- do.call(rbind, df_list) library("ggplot2") library("ggthemes") ggplot(df) + geom_bar(aes(x=time, y=steps), stat="identity") + theme_tufte() + scale_x_datetime(name="date", date_breaks="1 day", date_labels="%b-%d") ## ---- fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'---- df <- get_daily_data(cookie=cookie, what="floors", start_date="2016-02-15", end_date="2016-05-01") df$weekday <- format(df$time, "%A") avgs <- by(df$floors, df$weekday, mean) avgs <- data.frame(day=names(avgs), floors=as.numeric(avgs)) avgs$day <- factor(avgs$day, levels=avgs$day[c(4, 2, 6, 7, 5, 1, 3)]) ggplot(avgs) + geom_bar(aes(x=day, y=floors), stat="identity") + theme_tufte() + xlab("") + ylab("") + ggtitle("Average Floors by Day 2016-02-15 to 2016-05-01") + geom_text(aes(x=day,y=floors,label=round(floors, 1)), vjust=1.1, colour="white") + theme(axis.text.y=element_blank(), axis.ticks.y=element_blank()) + theme(plot.title=element_text(vjust=.5)) ## ---- fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'---- # don't do this... # mywt <- get_weight_data(cookie, start_date="2015-01-01", end_date="2015-05-01") start_date <- as.Date("2015-01-01") end_date <- as.Date("2015-05-01") wt_df_list <- list() # initialize a list to put the weight dataframes into in_range <- TRUE # indicator variable to tell when to exit while loop s_date <- start_date # date to start with during loop while(in_range){ e_date <- s_date + 14 new_df <- get_weight_data(cookie, start_date=as.character(s_date), end_date=as.character(e_date)) wt_df_list[[as.character(s_date)]] <- new_df s_date <- e_date + 1 if(e_date > end_date) in_range <- FALSE } wt_df <- do.call(rbind, wt_df_list) wt_df <- wt_df[!duplicated(wt_df$time), ] wt_df <- wt_df[order(wt_df$time), ] wt_df <- wt_df[as.Date(wt_df$time) >= start_date & as.Date(wt_df$time) <= end_date, ] step_df <- get_daily_data(cookie=cookie, what="steps", start_date="2015-01-01", end_date="2015-05-01") # get common date format to merge data sets... wt_df$date <- as.character(as.Date(wt_df$time)) step_df$date <- as.character(as.Date(step_df$time)) # merge by date df <- merge(wt_df, step_df, by="date") # now plot ggplot(df, aes(x=steps, y=weight)) + geom_point() + stat_smooth(se=FALSE) + theme_tufte() fitbitScraper/inst/doc/fitbitScraper-examples.Rmd0000644000176200001440000001365313073713356021676 0ustar liggesusers--- title: "fitbitScraper Examples" author: "Cory Nissen" date: "5/5/2016" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{fitbitScraper Examples} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ## Installation Install fitbitScraper as you would a normal library. It exists on [CRAN](https://cran.r-project.org/package=fitbitScraper), so a simple `install.packages("fitbitScraper")` should work. A development version exists on [Github](https://github.com/corynissen/fitbitScraper), and can be installed via [devtools](https://cran.r-project.org/package=devtools). `devtools::install_github("corynissen/fitbitScraper")` ## Usage I've stored my password in an environment variable called "FBPW". I'll use this to login to fitbit and generate a cookie that will be used for the subsequent requests. You can type it directly in the password field, but it is generally a best practice to use an environment variable instead. Fitbit allows login via Google and Facebook. This library only works with an email / password based login. ```{r} library("fitbitScraper") cookie <- login(email="corynissen@gmail.com", password=Sys.getenv("FBPW")) ``` Now you can run any of the other functions to get your data. Let's start with getting steps on a 15 minute interval for a given week... ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} dates <- seq(as.Date("2016-04-03"), as.Date("2016-04-09"), by="day") df_list <- lapply(dates, function(x) get_intraday_data(cookie=cookie, what="steps", as.character(x))) df <- do.call(rbind, df_list) library("ggplot2") library("ggthemes") ggplot(df) + geom_bar(aes(x=time, y=steps), stat="identity") + theme_tufte() + scale_x_datetime(name="date", date_breaks="1 day", date_labels="%b-%d") ``` You can get a daily summary of your data also. Here, I download data for the number of flights of stairs I climbed for the last two months. Then, compute the average number of flights of stairs by day, and graph it. Not surprisingly, I climb more stairs on the weekends when I'm home than I do at work during the week. Note that it is possible to get this data using `get_intraday_data()` for each day, but this is much more efficient using just one call to the fibit API for the entire date range instead of one API call per day. ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} df <- get_daily_data(cookie=cookie, what="floors", start_date="2016-02-15", end_date="2016-05-01") df$weekday <- format(df$time, "%A") avgs <- by(df$floors, df$weekday, mean) avgs <- data.frame(day=names(avgs), floors=as.numeric(avgs)) avgs$day <- factor(avgs$day, levels=avgs$day[c(4, 2, 6, 7, 5, 1, 3)]) ggplot(avgs) + geom_bar(aes(x=day, y=floors), stat="identity") + theme_tufte() + xlab("") + ylab("") + ggtitle("Average Floors by Day 2016-02-15 to 2016-05-01") + geom_text(aes(x=day,y=floors,label=round(floors, 1)), vjust=1.1, colour="white") + theme(axis.text.y=element_blank(), axis.ticks.y=element_blank()) + theme(plot.title=element_text(vjust=.5)) ``` Another thing to look at, especially if you have the [Aria scale](https://www.fitbit.com/aria), is your weight. You can record your weight manually in the fitbit app, which is how I do it, or the Aria scale will sync it automatically. Any how, let's graph my steps vs. weight for a time period and see if there seems to be a correlation. Data is returned for use in a graph on the fitbit page, so if you include a date range larger than two weeks or so, it returns data for a subset of the days in your range. Fitbit seems to play pretty loose with the start and end dates too. I want data from 2015-01-01 to 2015-05-01, so I'll break that into several requests to fitbit. ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} # don't do this... # mywt <- get_weight_data(cookie, start_date="2015-01-01", end_date="2015-05-01") start_date <- as.Date("2015-01-01") end_date <- as.Date("2015-05-01") wt_df_list <- list() # initialize a list to put the weight dataframes into in_range <- TRUE # indicator variable to tell when to exit while loop s_date <- start_date # date to start with during loop while(in_range){ e_date <- s_date + 14 new_df <- get_weight_data(cookie, start_date=as.character(s_date), end_date=as.character(e_date)) wt_df_list[[as.character(s_date)]] <- new_df s_date <- e_date + 1 if(e_date > end_date) in_range <- FALSE } wt_df <- do.call(rbind, wt_df_list) wt_df <- wt_df[!duplicated(wt_df$time), ] wt_df <- wt_df[order(wt_df$time), ] wt_df <- wt_df[as.Date(wt_df$time) >= start_date & as.Date(wt_df$time) <= end_date, ] step_df <- get_daily_data(cookie=cookie, what="steps", start_date="2015-01-01", end_date="2015-05-01") # get common date format to merge data sets... wt_df$date <- as.character(as.Date(wt_df$time)) step_df$date <- as.character(as.Date(step_df$time)) # merge by date df <- merge(wt_df, step_df, by="date") # now plot ggplot(df, aes(x=steps, y=weight)) + geom_point() + stat_smooth(se=FALSE) + theme_tufte() ``` That last example illustrates one of the limitations of retrieving the data the way this library does. Instead of using the "official" fitbit API, this library uses the API intended for their website developer to use to build the visualizations on the web dashboard. So, there's no public documentation. This results in situations like the last one where the weight data returned by that API call is intended to be used in a chart, so they don't need more than 20 points, so that's all that is returned, no matter how large the date range supplied is. Keep this in mind when you request data and use caution that you are being returned data for the same dates that you requested it for. fitbitScraper/inst/doc/fitbitScraper-examples.html0000644000176200001440000010741013073713356022113 0ustar liggesusers fitbitScraper Examples

fitbitScraper Examples

Cory Nissen

5/5/2016

Installation

Install fitbitScraper as you would a normal library. It exists on CRAN, so a simple install.packages("fitbitScraper") should work.

A development version exists on Github, and can be installed via devtools. devtools::install_github("corynissen/fitbitScraper")

Usage

I’ve stored my password in an environment variable called “FBPW”. I’ll use this to login to fitbit and generate a cookie that will be used for the subsequent requests. You can type it directly in the password field, but it is generally a best practice to use an environment variable instead. Fitbit allows login via Google and Facebook. This library only works with an email / password based login.

library("fitbitScraper")
cookie <- login(email="corynissen@gmail.com", password=Sys.getenv("FBPW"))

Now you can run any of the other functions to get your data. Let’s start with getting steps on a 15 minute interval for a given week…

dates <- seq(as.Date("2016-04-03"), as.Date("2016-04-09"), by="day")
df_list <- lapply(dates, function(x)
  get_intraday_data(cookie=cookie, what="steps", as.character(x)))
df <- do.call(rbind, df_list)

library("ggplot2")
library("ggthemes")
ggplot(df) + 
  geom_bar(aes(x=time, y=steps), stat="identity") + 
  theme_tufte() + 
  scale_x_datetime(name="date", date_breaks="1 day", date_labels="%b-%d")

You can get a daily summary of your data also. Here, I download data for the number of flights of stairs I climbed for the last two months. Then, compute the average number of flights of stairs by day, and graph it. Not surprisingly, I climb more stairs on the weekends when I’m home than I do at work during the week. Note that it is possible to get this data using get_intraday_data() for each day, but this is much more efficient using just one call to the fibit API for the entire date range instead of one API call per day.

df <- get_daily_data(cookie=cookie, what="floors", start_date="2016-02-15",
                     end_date="2016-05-01")
df$weekday <- format(df$time, "%A")
avgs <- by(df$floors, df$weekday, mean)
avgs <- data.frame(day=names(avgs), floors=as.numeric(avgs))
avgs$day <- factor(avgs$day, levels=avgs$day[c(4, 2, 6, 7, 5, 1, 3)])

ggplot(avgs) + 
  geom_bar(aes(x=day, y=floors), stat="identity") + 
  theme_tufte() + 
  xlab("") + 
  ylab("") + 
  ggtitle("Average Floors by Day 2016-02-15 to 2016-05-01") + 
  geom_text(aes(x=day,y=floors,label=round(floors, 1)),
            vjust=1.1, colour="white") + 
  theme(axis.text.y=element_blank(), axis.ticks.y=element_blank()) + 
  theme(plot.title=element_text(vjust=.5)) 

Another thing to look at, especially if you have the Aria scale, is your weight. You can record your weight manually in the fitbit app, which is how I do it, or the Aria scale will sync it automatically. Any how, let’s graph my steps vs. weight for a time period and see if there seems to be a correlation. Data is returned for use in a graph on the fitbit page, so if you include a date range larger than two weeks or so, it returns data for a subset of the days in your range. Fitbit seems to play pretty loose with the start and end dates too. I want data from 2015-01-01 to 2015-05-01, so I’ll break that into several requests to fitbit.

# don't do this...
# mywt <- get_weight_data(cookie, start_date="2015-01-01", end_date="2015-05-01")
start_date <- as.Date("2015-01-01")
end_date <- as.Date("2015-05-01")
wt_df_list <- list()      # initialize a list to put the weight dataframes into
in_range <- TRUE          # indicator variable to tell when to exit while loop
s_date <- start_date      # date to start with during loop
while(in_range){
  e_date <- s_date + 14
  new_df <- get_weight_data(cookie, start_date=as.character(s_date),
                            end_date=as.character(e_date))
  wt_df_list[[as.character(s_date)]] <- new_df
  s_date <- e_date + 1
  if(e_date > end_date) in_range <- FALSE
}
wt_df <- do.call(rbind, wt_df_list)
wt_df <- wt_df[!duplicated(wt_df$time), ]
wt_df <- wt_df[order(wt_df$time), ]
wt_df <- wt_df[as.Date(wt_df$time) >= start_date &
               as.Date(wt_df$time) <= end_date, ]

step_df <- get_daily_data(cookie=cookie, what="steps", start_date="2015-01-01",
                          end_date="2015-05-01")

# get common date format to merge data sets...
wt_df$date <- as.character(as.Date(wt_df$time))
step_df$date <- as.character(as.Date(step_df$time))

# merge by date
df <- merge(wt_df, step_df, by="date")

# now plot
ggplot(df, aes(x=steps, y=weight)) + 
  geom_point() + 
  stat_smooth(se=FALSE) + 
  theme_tufte()

That last example illustrates one of the limitations of retrieving the data the way this library does. Instead of using the “official” fitbit API, this library uses the API intended for their website developer to use to build the visualizations on the web dashboard. So, there’s no public documentation. This results in situations like the last one where the weight data returned by that API call is intended to be used in a chart, so they don’t need more than 20 points, so that’s all that is returned, no matter how large the date range supplied is. Keep this in mind when you request data and use caution that you are being returned data for the same dates that you requested it for.

fitbitScraper/NAMESPACE0000644000176200001440000000033213073713347014300 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(get_activity_data) export(get_daily_data) export(get_intraday_data) export(get_premium_export) export(get_sleep_data) export(get_weight_data) export(login) fitbitScraper/NEWS.md0000644000176200001440000000405113073713347014161 0ustar liggesusers ### fitbitScraper 0.1.8 * added minutesSedentary data to 'get_daily_data' [(14)](https://github.com/corynissen/fitbitScraper/issues/14) * fixed bug in the column names in 'get_daily_data' for getTimeInHeartRateZonesPerDay [(9)](https://github.com/corynissen/fitbitScraper/issues/9) [(13)](https://github.com/corynissen/fitbitScraper/issues/13) * if login returns a cookie that is character(0), throw error [(10)](https://github.com/corynissen/fitbitScraper/issues/10) ### fitbitScraper 0.1.7 * added vignette ### fitbitScraper 0.1.6 * switch from RJSONIO to jsonlite ### fitbitScraper 0.1.5 * use real URL in DESCRIPTION * added <> around URLs in DESCRIPTION * added methods and utils to imports in DESCRIPTION * added corresponding methods:: and utils:: in code * changed get_activity_data() function to have a working end_date. * pull request #7 calories burned vs intake * pull request #5 Add check.names=T for creating data.frames * pull request #4 slight changes to sleep variable names * pull request #3 Update login.R ### fitbitScraper 0.1.4 * added get_activity_data() function * added "getRestingHeartRateData" to get_daily_data() function * added rememberMe parameter to login function * merged pull request #2, a change to the login function ### fitbitScraper 0.1.3 * Changed the API calls to match changes on fitbit end of things. ### fitbitScraper 0.1.2 * Added get_sleep_data() * Added get_premium_export() * Changed output column of get_daily_data(), get_15_min_data(), and get_weight_data() to correspond to the data type requested... for example: "weight" instead of "data"", "steps" instead of "data" * Added heart-rate for get_15_min_data() and get_daily_data() * added get_intraday_data() * Deprecated get_15_min_data(), use get_intraday_data() instead ### fitbitScraper 0.1.1 * Basic checks included for arguments * tz added to the return dataframes as.POSIXct date field * documentation cleanup ### fitbitScraper 0.1 * No error checking * Three functions: login, get_daily_data, get_15_min_data fitbitScraper/R/0000755000176200001440000000000013073713347013264 5ustar liggesusersfitbitScraper/R/get_premium_export.R0000644000176200001440000000755313073713347017337 0ustar liggesusers#' Get official data export from fitbit.com premium #' #' Get official data export from fitbit premium using cookie returned from login function. This should be used over individual calls to get_daily_data(), etc. if you subscribe to premium and data export is allowed. I'm not subscribed to premium, but it works for me... #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param what What data you wish to be returned. Options include "BODY", "FOODS", "ACTIVITIES", "SLEEP" #' @param start_date Date in YYYY-MM-DD format #' @param end_date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A list with two things #' \item{summary}{A list of sleep summary values} #' \item{df}{A data frame containing various sleep values over time} #' @examples #' \dontrun{ #' get_premium_export(cookie, what="ACTIVITIES", start_date="2015-01-13", end_date="2015-01-20") #' } #' get_premium_export get_premium_export <- function(cookie, what="ACTIVITIES", start_date="2015-01-13", end_date="2015-01-20"){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(what)){stop("what must be a character string")} if(!is.character(start_date)){stop("start_date must be a character string")} if(!is.character(end_date)){stop("end_date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", start_date)){stop('start_date must have format "YYYY-MM-DD"')} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", end_date)){stop('end_date must have format "YYYY-MM-DD"')} if(!what %in% c("BODY", "FOODS", "ACTIVITIES", "SLEEP")){ stop('what must be one of "BODY", "FOODS", "ACTIVITIES", "SLEEP"') } # as of 5/2015-ish, the date format is not MM/DD/YYYY start_date <- format(as.Date(start_date), "%m/%d/%Y") end_date <- format(as.Date(end_date), "%m/%d/%Y") url <- "https://www.fitbit.com/export/user/data" header <- list("Content-Type"="application/x-www-form-urlencoded", "u"=cookie, "Host"="www.fitbit.com", "Origin"="https://www.fitbit.com", "Referer"="https://www.fitbit.com/export/user/data", "User-Agent"="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36", "X-Requested-With"="XMLHttpRequest") body <- list("export"="true", "dataPeriod.periodType"="CUSTOM", "startDate"=start_date, "endDate"=end_date, "dataExportType"=what, "fileFormat"="CSV") response <- httr::POST(url, header=header, body=body, httr::config(cookie=cookie)) if(response$status_code!=200){ stop("problem with request, this may be available only for premium subscribers") } file_id <- methods::as(response, "character") file_id <- jsonlite::fromJSON(file_id) file_id <- file_id["fileIdentifier"] # see if file ready for download get_file_status <- function(file_id){ is_ready <- httr::GET(paste0("https://www.fitbit.com/premium/export?isExportedFileReady=true&fileIdentifier=", file_id)) if("fileIsReady" %in% names(httr::content(is_ready))){ is_ready <- httr::content(is_ready)$fileIsReady }else{ stop("file_id not found while retrieving file status") } return(is_ready) } start <- Sys.time() is_ready <- get_file_status(file_id) while(!is_ready){ if(Sys.time() - start > 10){ stop("timeout waiting for file to generate") } Sys.sleep(.5) is_ready <- get_file_status(file_id) } a <- httr::GET(paste0("https://www.fitbit.com/premium/export/download/", file_id)) df <- utils::read.csv(text=methods::as(a, "character"), skip=1, stringsAsFactors=F) return(df) } fitbitScraper/R/login.R0000644000176200001440000000403213073713347014516 0ustar liggesusers#' Login to fitbit.com and get cookie #' #' Get the login cookie after login at www.fitbit.com #' @param email Email address used to login to fitbit.com #' @param password Password used to login to fitbit.com #' @param rememberMe Value for rememberMe during login, default is FALSE, but changing to TRUE may help with login issues #' @keywords login #' @export #' @return A string containing the cookie that is returned after login at www.fitbit.com #' @examples #' \dontrun{ #' cookie <- login(email="corynissengmail.com", password="mypasswordhere") #' } #' login login <- function(email, password, rememberMe=FALSE){ if(!is.character(email)){stop("email must be a character string")} if(!is.character(password)){stop("password must be a character string")} rememberMe <- ifelse(rememberMe, "true", "false") url <- "https://www.fitbit.com/login" headers <- list("Host" = "www.fitbit.com", "Connection" = "keep-alive", "Content-Length" = "278", "Cache-Control" = "max-age=0", "Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Origin" = "https://www.fitbit.com", "User-Agent" = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36", "Content-Type" = "application/x-www-form-urlencoded", "Referer" = "https://www.fitbit.com/login", "Accept-Encoding" = "gzip, deflate", "Accept-Language" = "en-US,en;q=0.8") body <- list("email"=email, "password"=password, "rememberMe"=rememberMe, "login"="Log In") a <- httr::POST(url, headers=headers, body=body) cookie <- a$cookies$u if(is.null(cookie)){ all_cookies <- a$cookies cookie <- all_cookies[grep("^u$", all_cookies$name, ignore.case=F),"value"] if(is.null(cookie) | identical(cookie, character(0))){ stop("login failed") } } return(cookie) } fitbitScraper/R/get_weight_data.R0000644000176200001440000000323713073713347016533 0ustar liggesusers#' Get weight data from fitbit.com #' #' Get weight data from fitbit using cookie returned from login function #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param start_date Date in YYYY-MM-DD format #' @param end_date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A dataframe with two columns: #' \item{time}{A POSIXct time value} #' \item{weight}{The data column corresponding to weight} #' @examples #' \dontrun{ #' get_weight_data(cookie, start_date="2015-01-13", end_date="2015-01-20") #' } #' get_weight_data get_weight_data <- function(cookie, start_date, end_date){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(start_date)){stop("start_date must be a character string")} if(!is.character(end_date)){stop("end_date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", start_date)){stop('start_date must have format "YYYY-MM-DD"')} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", end_date)){stop('end_date must have format "YYYY-MM-DD"')} url <- "https://www.fitbit.com/graph/getNewGraphData" query <- list("type" = "weight", "dateFrom" = start_date, "dateTo" = end_date) response <- httr::GET(url, query=query, httr::config(cookie=cookie)) dat_string <- methods::as(response, "character") dat_list <- jsonlite::fromJSON(dat_string) df <- dat_list[["graph"]][["dataSets"]][["weight"]][["dataPoints"]] names(df)[1:2] <- c("time", "weight") tz <- Sys.timezone() if(is.null(tz)){tz <- format(Sys.time(),"%Z")} df$time <- as.POSIXct(df$time, "%Y-%m-%d %H:%M:%S", tz=tz) return(df) } fitbitScraper/R/get_intraday_data.R0000644000176200001440000000456513073713347017064 0ustar liggesusers#' Get intraday data from fitbit.com #' #' Get intraday data from fitbit using cookie returned from login function #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param what What data you wish to be returned. Options include "steps", "distance", "floors", "active-minutes", "calories-burned", "heart-rate" #' @param date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A dataframe with two columns: #' \item{time}{A POSIXct time value} #' \item{data}{The data column corresponding to the choice of "what"} #' @examples #' \dontrun{ #' get_intraday_data(cookie, what="steps", date="2015-01-20") #' } #' get_intraday_data get_intraday_data <- function(cookie, what="steps", date){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(what)){stop("what must be a character string")} if(!is.character(date)){stop("date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", date)){stop('date must have format "YYYY-MM-DD"')} if(!what %in% c("steps", "distance", "floors", "active-minutes", "calories-burned", "heart-rate")){ stop('what must be one of "steps", "distance", "floors", "active-minutes", "calories-burned", "heart-rate"') } url <- "https://www.fitbit.com/ajaxapi" request <- paste0('{"template":"/ajaxTemplate.jsp","serviceCalls":[{"name":"activityTileData","args":{"date":"', date, '","dataTypes":"', what, '"},"method":"getIntradayData"}]}' ) csrfToken <- stringr::str_extract(cookie, "[A-Z0-9]{8}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[0-9A-Z]{12}") body <- list(request=request, csrfToken = csrfToken) response <- httr::POST(url, body=body, httr::config(cookie=cookie)) dat_string <- methods::as(response, "character") dat_list <- jsonlite::fromJSON(dat_string) df <- dat_list[["dataSets"]][["activity"]][["dataPoints"]][[1]] if(what=="heart-rate"){ tz <- Sys.timezone() if(is.null(tz)){tz <- format(Sys.time(),"%Z")} df$time <- as.POSIXct(df$dateTime, "%Y-%m-%d %H:%M:%S", tz=tz) }else{ names(df)[1:2] <- c("time", what) tz <- Sys.timezone() if(is.null(tz)){tz <- format(Sys.time(),"%Z")} df$time <- as.POSIXct(df$time, "%Y-%m-%d %H:%M:%S", tz=tz) } return(df) } fitbitScraper/R/get_sleep_data.R0000644000176200001440000000435313073713347016354 0ustar liggesusers#' Get sleep data from fitbit.com #' #' Get sleep data from fitbit using cookie returned from login function #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param start_date Date in YYYY-MM-DD format #' @param end_date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A list with two things #' \item{summary}{A list of sleep summary values} #' \item{df}{A data frame containing various sleep values over time} #' @examples #' \dontrun{ #' get_sleep_data(cookie, start_date="2015-01-13", end_date="2015-01-20") #' } #' get_sleep_data get_sleep_data <- function(cookie, start_date="2015-01-13", end_date="2015-01-20"){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(start_date)){stop("start_date must be a character string")} if(!is.character(end_date)){stop("end_date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", start_date)){stop('start_date must have format "YYYY-MM-DD"')} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", end_date)){stop('end_date must have format "YYYY-MM-DD"')} url <- "https://www.fitbit.com/ajaxapi" request <- paste0('{"template":"/ajaxTemplate.jsp","serviceCalls":[{"name":"activityTileData","args":{"dateFrom":"', start_date, '","dateTo":"', end_date, '"},"method":"getSleepTileData"}]}' ) csrfToken <- stringr::str_extract(cookie, "[A-Z0-9]{8}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[0-9A-Z]{12}") body <- list(request=request, csrfToken = csrfToken) response <- httr::POST(url, body=body, httr::config(cookie=cookie)) dat_string <- methods::as(response, "character") dat_list <- jsonlite::fromJSON(dat_string) if("hasLoggedSleep" %in% names(dat_list)){ summary <- list(avgSleepDuration = dat_list$avgSleepDuration, avgSleepTime = dat_list$avgSleepTime, avgSleepScore = dat_list$avgSleepScore, avgGraphicPercent = dat_list$avgGraphicPercent) # get individual day data df <- dat_list[["entries"]] }else{ stop("No sleep data available") } return(list(summary=summary, df=df)) } fitbitScraper/R/get_daily_data.R0000644000176200001440000001075313073713347016347 0ustar liggesusers#' Get daily data from fitbit.com #' #' Get daily data from fitbit using cookie returned from login function #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param what What data you wish to be returned. Options include "steps", "distance", "floors", "minutesVery", "caloriesBurnedVsIntake", "minutesSedentary", "getTimeInHeartRateZonesPerDay", "getRestingHeartRateData" #' @param start_date Date in YYYY-MM-DD format #' @param end_date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A dataframe with two columns: #' \item{time}{A POSIXct time value} #' \item{data}{The data column corresponding to the choice of "what"} #' @examples #' \dontrun{ #' get_daily_data(cookie, what="steps", start_date="2015-01-13", end_date="2015-01-20") #' } #' get_daily_data get_daily_data <- function(cookie, what="steps", start_date, end_date){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(what)){stop("what must be a character string")} if(!is.character(start_date)){stop("start_date must be a character string")} if(!is.character(end_date)){stop("end_date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", start_date)){ stop('start_date must have format "YYYY-MM-DD"') } if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", end_date)){ stop('end_date must have format "YYYY-MM-DD"') } if(!what %in% c("steps", "distance", "floors", "minutesVery", "caloriesBurnedVsIntake", "minutesSedentary", "getTimeInHeartRateZonesPerDay", "getRestingHeartRateData")){ stop('what must be one of "steps", "distance", "floors", "minutesVery", "caloriesBurnedVsIntake", "minutesSedentary", "getTimeInHeartRateZonesPerDay", "getRestingHeartRateData"') } if(what %in% c("getTimeInHeartRateZonesPerDay", "getRestingHeartRateData")){ url <- "https://www.fitbit.com/ajaxapi" request <- paste0('{"template":"/ajaxTemplate.jsp","serviceCalls":[{"name":"activityTileData","args":{"startDate":"', start_date, '","endDate":"', end_date, '"},"method":"', what, '"}]}' ) csrfToken <- stringr::str_extract(cookie, "[A-Z0-9]{8}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[0-9A-Z]{12}") body <- list(request=request, csrfToken = csrfToken) response <- httr::POST(url, body=body, httr::config(cookie=cookie)) }else{ url <- "https://www.fitbit.com/graph/getNewGraphData" query <- list("type" = what, "dateFrom" = start_date, "dateTo" = end_date, "granularity" = "DAILY", "hidePrecreationData" = "false") response <- httr::GET(url, query=query, httr::config(cookie=cookie)) } dat_string <- methods::as(response, "character") dat_list <- jsonlite::fromJSON(dat_string) if(what=="getTimeInHeartRateZonesPerDay"){ if(length(dat_list$value)==0){ stop("No getTimeInHeartRateZonesPerDay available") } df <- cbind(dat_list$dateTime, dat_list$value, stringsAsFactors=FALSE) names(df)[1] <- "time" names(df)[names(df)=="IN_DEFAULT_ZONE_1"] <- "zone1" names(df)[names(df)=="IN_DEFAULT_ZONE_2"] <- "zone2" names(df)[names(df)=="IN_DEFAULT_ZONE_3"] <- "zone3" }else if(what=="getRestingHeartRateData"){ if(length(dat_list$dataPoints)==0){ stop("No getRestingHeartRateData available") } df <- dat_list$dataPoints df <- df[, c("date", "value")] names(df)[1:2] <- c("time", "restingHeartRate") }else if(what=="caloriesBurnedVsIntake"){ df_burn <- dat_list[["graph"]][["dataSets"]][["activity"]][["dataPoints"]] df_int <- dat_list[["graph"]][["dataSets"]][["caloriesIntake"]][["dataPoints"]] names(df_burn)[1:2] <- c("time", "caloriesBurned") names(df_int)[1:2] <- c("time", "caloriesIntake") df <- merge(df_burn, df_int, by="time") }else{ df <- dat_list[["graph"]][["dataSets"]][["activity"]][["dataPoints"]] names(df)[1:2] <- c("time", what) } if(what=="getRestingHeartRateData"){ tz <- Sys.timezone() if(is.null(tz)){tz <- format(Sys.time(),"%Z")} df$time <- as.POSIXct(df$time, "%Y-%m-%d", tz=tz) }else{ tz <- Sys.timezone() if(is.null(tz)){tz <- format(Sys.time(),"%Z")} df$time <- as.POSIXct(df$time, "%Y-%m-%d %H:%M:%S", tz=tz) } return(df) } fitbitScraper/R/get_activity_data.R0000644000176200001440000000454313073713347017101 0ustar liggesusers#' Get activity data from fitbit.com #' #' Get activity data from fitbit using cookie returned from login function #' @param cookie Cookie returned after login, specifically the "u" cookie #' @param end_date Date in YYYY-MM-DD format #' @keywords data #' @export #' @return A dataframe with raw output from Fitbit #' @examples #' \dontrun{ #' get_activity_data(cookie, end_date="2015-01-20") #' } #' get_activity_data get_activity_data <- function(cookie, end_date){ if(!is.character(cookie)){stop("cookie must be a character string")} if(!is.character(end_date)){stop("end_date must be a character string")} if(!grepl("[0-9]{4}-[0-9]{2}-[0-9]{2}", end_date)){stop('end_date must have format "YYYY-MM-DD"')} url <- "https://www.fitbit.com/ajaxapi" request <- paste0('{"serviceCalls":[{"id":"GET /api/2/user/activities/logs","name":"user","method":"getActivitiesLogs","args":{', '"beforeDate":"', end_date, 'T00:00:00",', '"period":"day","offset":0,"limit":100}},{"id":"GET /api/2/user/activities/logs/summary","name":"user","method":"getActivitiesLogsSummary","args":{"fromDate":"', end_date, '","toDate":"', end_date, '","period":"day","offset":0,"limit":10}}],"template":"activities/modules/models/ajax.response.json.jsp"}' ) csrfToken <- stringr::str_extract(cookie, "[A-Z0-9]{8}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[A-Z0-9]{4}\\-[0-9A-Z]{12}") body <- list(request=request, csrfToken = csrfToken) response <- httr::POST(url, body=body, httr::config(cookie=cookie)) dat_string <- methods::as(response, "character") dat_list <- jsonlite::fromJSON(dat_string) if("GET /api/2/user/activities/logs" %in% names(dat_list)){ df <- dat_list[["GET /api/2/user/activities/logs"]]["result"][[1]] }else{ df <- NULL print("unable to retrieve activities data") } tz <- Sys.timezone() if(is.null(tz) | is.na(tz)){tz <- format(Sys.time(),"%Z")} df$start_datetime <- as.POSIXct(paste0(df$date, " ", df$formattedStartTime), format="%Y-%m-%d %H:%M", tz=tz) df$end_datetime <- as.POSIXct(paste0(df$date, " ", df$formattedEndTime), format="%Y-%m-%d %H:%M", tz=tz) return(df) } fitbitScraper/vignettes/0000755000176200001440000000000013073713356015073 5ustar liggesusersfitbitScraper/vignettes/fitbitScraper-examples.Rmd0000644000176200001440000001365313073713347022164 0ustar liggesusers--- title: "fitbitScraper Examples" author: "Cory Nissen" date: "5/5/2016" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{fitbitScraper Examples} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ## Installation Install fitbitScraper as you would a normal library. It exists on [CRAN](https://cran.r-project.org/package=fitbitScraper), so a simple `install.packages("fitbitScraper")` should work. A development version exists on [Github](https://github.com/corynissen/fitbitScraper), and can be installed via [devtools](https://cran.r-project.org/package=devtools). `devtools::install_github("corynissen/fitbitScraper")` ## Usage I've stored my password in an environment variable called "FBPW". I'll use this to login to fitbit and generate a cookie that will be used for the subsequent requests. You can type it directly in the password field, but it is generally a best practice to use an environment variable instead. Fitbit allows login via Google and Facebook. This library only works with an email / password based login. ```{r} library("fitbitScraper") cookie <- login(email="corynissen@gmail.com", password=Sys.getenv("FBPW")) ``` Now you can run any of the other functions to get your data. Let's start with getting steps on a 15 minute interval for a given week... ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} dates <- seq(as.Date("2016-04-03"), as.Date("2016-04-09"), by="day") df_list <- lapply(dates, function(x) get_intraday_data(cookie=cookie, what="steps", as.character(x))) df <- do.call(rbind, df_list) library("ggplot2") library("ggthemes") ggplot(df) + geom_bar(aes(x=time, y=steps), stat="identity") + theme_tufte() + scale_x_datetime(name="date", date_breaks="1 day", date_labels="%b-%d") ``` You can get a daily summary of your data also. Here, I download data for the number of flights of stairs I climbed for the last two months. Then, compute the average number of flights of stairs by day, and graph it. Not surprisingly, I climb more stairs on the weekends when I'm home than I do at work during the week. Note that it is possible to get this data using `get_intraday_data()` for each day, but this is much more efficient using just one call to the fibit API for the entire date range instead of one API call per day. ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} df <- get_daily_data(cookie=cookie, what="floors", start_date="2016-02-15", end_date="2016-05-01") df$weekday <- format(df$time, "%A") avgs <- by(df$floors, df$weekday, mean) avgs <- data.frame(day=names(avgs), floors=as.numeric(avgs)) avgs$day <- factor(avgs$day, levels=avgs$day[c(4, 2, 6, 7, 5, 1, 3)]) ggplot(avgs) + geom_bar(aes(x=day, y=floors), stat="identity") + theme_tufte() + xlab("") + ylab("") + ggtitle("Average Floors by Day 2016-02-15 to 2016-05-01") + geom_text(aes(x=day,y=floors,label=round(floors, 1)), vjust=1.1, colour="white") + theme(axis.text.y=element_blank(), axis.ticks.y=element_blank()) + theme(plot.title=element_text(vjust=.5)) ``` Another thing to look at, especially if you have the [Aria scale](https://www.fitbit.com/aria), is your weight. You can record your weight manually in the fitbit app, which is how I do it, or the Aria scale will sync it automatically. Any how, let's graph my steps vs. weight for a time period and see if there seems to be a correlation. Data is returned for use in a graph on the fitbit page, so if you include a date range larger than two weeks or so, it returns data for a subset of the days in your range. Fitbit seems to play pretty loose with the start and end dates too. I want data from 2015-01-01 to 2015-05-01, so I'll break that into several requests to fitbit. ```{r, fig.height=4, fig.width=5, message=FALSE, warning=FALSE, fig.align='center'} # don't do this... # mywt <- get_weight_data(cookie, start_date="2015-01-01", end_date="2015-05-01") start_date <- as.Date("2015-01-01") end_date <- as.Date("2015-05-01") wt_df_list <- list() # initialize a list to put the weight dataframes into in_range <- TRUE # indicator variable to tell when to exit while loop s_date <- start_date # date to start with during loop while(in_range){ e_date <- s_date + 14 new_df <- get_weight_data(cookie, start_date=as.character(s_date), end_date=as.character(e_date)) wt_df_list[[as.character(s_date)]] <- new_df s_date <- e_date + 1 if(e_date > end_date) in_range <- FALSE } wt_df <- do.call(rbind, wt_df_list) wt_df <- wt_df[!duplicated(wt_df$time), ] wt_df <- wt_df[order(wt_df$time), ] wt_df <- wt_df[as.Date(wt_df$time) >= start_date & as.Date(wt_df$time) <= end_date, ] step_df <- get_daily_data(cookie=cookie, what="steps", start_date="2015-01-01", end_date="2015-05-01") # get common date format to merge data sets... wt_df$date <- as.character(as.Date(wt_df$time)) step_df$date <- as.character(as.Date(step_df$time)) # merge by date df <- merge(wt_df, step_df, by="date") # now plot ggplot(df, aes(x=steps, y=weight)) + geom_point() + stat_smooth(se=FALSE) + theme_tufte() ``` That last example illustrates one of the limitations of retrieving the data the way this library does. Instead of using the "official" fitbit API, this library uses the API intended for their website developer to use to build the visualizations on the web dashboard. So, there's no public documentation. This results in situations like the last one where the weight data returned by that API call is intended to be used in a chart, so they don't need more than 20 points, so that's all that is returned, no matter how large the date range supplied is. Keep this in mind when you request data and use caution that you are being returned data for the same dates that you requested it for. fitbitScraper/README.md0000644000176200001440000000275513073713347014353 0ustar liggesusers ### fitbitScraper 0.1.8 New changes: * Added minutesSedentary data to 'get_daily_data' * fixed bug in the column names in ‘get_daily_data’ for getTimeInHeartRateZonesPerDay * if login returns a cookie that is character(0), throw error This package scrapes data from fitbit.com It only works if you use email / password to login. Not sure about facebook or google login. Usage: ```R install.packages("fitbitScraper") library("fitbitScraper") cookie <- login(email="corynissen@gmail.com", password="mypassword") # 15_min_data "what" options: "steps", "distance", "floors", "active-minutes", "calories-burned" df <- get_intraday_data(cookie, what="steps", date="2015-01-21") library("ggplot2") ggplot(df) + geom_bar(aes(x=time, y=data, fill=data), stat="identity") + xlab("") +ylab("steps") + theme(axis.ticks.x=element_blank(), panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank(), panel.grid.minor.y = element_blank(), panel.background=element_blank(), panel.grid.major.y=element_line(colour="gray", size=.1), legend.position="none") # daily_data "what" options: "steps", "distance", "floors", "minutesVery", "caloriesBurnedVsIntake" df <- get_daily_data(cookie, what="steps", start_date="2015-01-13", end_date="2015-01-20") ggplot(df) + geom_point(aes(x=time, y=data)) ``` fitbitScraper/MD50000644000176200001440000000244613073773730013403 0ustar liggesusersee7887a6f26ec6cbab51f3e9a55b54bf *DESCRIPTION d499114c8fb7674b84d73553dd6e8d9a *LICENSE af05ec54f552800fae2fa87191cbef9c *NAMESPACE ac61a04f6ddab4b74ed5146ba2e9e9ac *NEWS.md 4c36988d3c86d315746c10bf66b3ca0e *R/get_activity_data.R 5f76691fa4c46dbd92c24f360593b031 *R/get_daily_data.R bbdfa193a0b307c8f634c89681ad87d1 *R/get_intraday_data.R c1b92b4d6f2af001a7c7227c927360f4 *R/get_premium_export.R a363b6cd2faa8a8ccfdb2052dfb42540 *R/get_sleep_data.R e541d7ca220d36967d1e210f94f6ce68 *R/get_weight_data.R f4556f117ee5deccbebf783f1eb1b107 *R/login.R af81496badfc842745acd1abb2580651 *README.md 0931549ad4694e9876f3910fcce3a896 *build/vignette.rds 0834d2d5146972b7fcf319fadfbb7c37 *inst/doc/fitbitScraper-examples.R c7eceade09e11fbd5338f2da0b26a6d6 *inst/doc/fitbitScraper-examples.Rmd 80dc573c8e9f9468f91ee98b67d79f36 *inst/doc/fitbitScraper-examples.html ef46e34905fe4de65d9720d6faf659d5 *man/get_activity_data.Rd 2fb841c269e0c885e24c7827c14713be *man/get_daily_data.Rd d1d62e7f5a4203d3981365b73484047b *man/get_intraday_data.Rd 95e7c34caf634955d90ececb5e34fddf *man/get_premium_export.Rd 30bc88bbfe3cf9130a56cdf2c4f00620 *man/get_sleep_data.Rd 80c17df442cb83910c7c0f512f3e535b *man/get_weight_data.Rd cfb2afc79b3ca5875d9898049cb6ecc0 *man/login.Rd c7eceade09e11fbd5338f2da0b26a6d6 *vignettes/fitbitScraper-examples.Rmd fitbitScraper/build/0000755000176200001440000000000013073713356014162 5ustar liggesusersfitbitScraper/build/vignette.rds0000644000176200001440000000032613073713356016522 0ustar liggesusersb```b`ffb`b2 1# 'J,I, N.J,H-MH-I- MAS)RM42JrsДJja:z `aBǚa/KjAj^ HvѴpxVaaqIY0AAn0Ez0?Ht&${+%$Q/nNfitbitScraper/DESCRIPTION0000644000176200001440000000143413073773730014575 0ustar liggesusersPackage: fitbitScraper Title: Scrapes Data from Fitbit Version: 0.1.8 Author: Cory Nissen [aut, cre] Maintainer: Cory Nissen Description: Scrapes data from Fitbit . This does not use the official API, but instead uses the API that the web dashboard uses to generate the graphs displayed on the dashboard after login at . Depends: R (>= 3.0.0) License: MIT + file LICENSE LazyData: true Imports: httr, stringr, jsonlite, methods, utils URL: https://github.com/corynissen/fitbitScraper RoxygenNote: 6.0.1 Suggests: knitr, rmarkdown, ggplot2, ggthemes VignetteBuilder: knitr NeedsCompilation: no Packaged: 2017-04-13 15:19:10 UTC; 60018847 Repository: CRAN Date/Publication: 2017-04-13 22:12:40 UTC fitbitScraper/man/0000755000176200001440000000000013073713347013636 5ustar liggesusersfitbitScraper/man/get_sleep_data.Rd0000644000176200001440000000147513073713347017074 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_sleep_data.R \name{get_sleep_data} \alias{get_sleep_data} \title{Get sleep data from fitbit.com} \usage{ get_sleep_data(cookie, start_date = "2015-01-13", end_date = "2015-01-20") } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{start_date}{Date in YYYY-MM-DD format} \item{end_date}{Date in YYYY-MM-DD format} } \value{ A list with two things \item{summary}{A list of sleep summary values} \item{df}{A data frame containing various sleep values over time} } \description{ Get sleep data from fitbit using cookie returned from login function } \examples{ \dontrun{ get_sleep_data(cookie, start_date="2015-01-13", end_date="2015-01-20") } get_sleep_data } \keyword{data} fitbitScraper/man/get_daily_data.Rd0000644000176200001440000000202213073713347017053 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_daily_data.R \name{get_daily_data} \alias{get_daily_data} \title{Get daily data from fitbit.com} \usage{ get_daily_data(cookie, what = "steps", start_date, end_date) } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{what}{What data you wish to be returned. Options include "steps", "distance", "floors", "minutesVery", "caloriesBurnedVsIntake", "minutesSedentary", "getTimeInHeartRateZonesPerDay", "getRestingHeartRateData"} \item{start_date}{Date in YYYY-MM-DD format} \item{end_date}{Date in YYYY-MM-DD format} } \value{ A dataframe with two columns: \item{time}{A POSIXct time value} \item{data}{The data column corresponding to the choice of "what"} } \description{ Get daily data from fitbit using cookie returned from login function } \examples{ \dontrun{ get_daily_data(cookie, what="steps", start_date="2015-01-13", end_date="2015-01-20") } get_daily_data } \keyword{data} fitbitScraper/man/get_weight_data.Rd0000644000176200001440000000142613073713347017247 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_weight_data.R \name{get_weight_data} \alias{get_weight_data} \title{Get weight data from fitbit.com} \usage{ get_weight_data(cookie, start_date, end_date) } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{start_date}{Date in YYYY-MM-DD format} \item{end_date}{Date in YYYY-MM-DD format} } \value{ A dataframe with two columns: \item{time}{A POSIXct time value} \item{weight}{The data column corresponding to weight} } \description{ Get weight data from fitbit using cookie returned from login function } \examples{ \dontrun{ get_weight_data(cookie, start_date="2015-01-13", end_date="2015-01-20") } get_weight_data } \keyword{data} fitbitScraper/man/get_activity_data.Rd0000644000176200001440000000117613073713347017616 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_activity_data.R \name{get_activity_data} \alias{get_activity_data} \title{Get activity data from fitbit.com} \usage{ get_activity_data(cookie, end_date) } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{end_date}{Date in YYYY-MM-DD format} } \value{ A dataframe with raw output from Fitbit } \description{ Get activity data from fitbit using cookie returned from login function } \examples{ \dontrun{ get_activity_data(cookie, end_date="2015-01-20") } get_activity_data } \keyword{data} fitbitScraper/man/get_premium_export.Rd0000644000176200001440000000230113073713347020037 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_premium_export.R \name{get_premium_export} \alias{get_premium_export} \title{Get official data export from fitbit.com premium} \usage{ get_premium_export(cookie, what = "ACTIVITIES", start_date = "2015-01-13", end_date = "2015-01-20") } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{what}{What data you wish to be returned. Options include "BODY", "FOODS", "ACTIVITIES", "SLEEP"} \item{start_date}{Date in YYYY-MM-DD format} \item{end_date}{Date in YYYY-MM-DD format} } \value{ A list with two things \item{summary}{A list of sleep summary values} \item{df}{A data frame containing various sleep values over time} } \description{ Get official data export from fitbit premium using cookie returned from login function. This should be used over individual calls to get_daily_data(), etc. if you subscribe to premium and data export is allowed. I'm not subscribed to premium, but it works for me... } \examples{ \dontrun{ get_premium_export(cookie, what="ACTIVITIES", start_date="2015-01-13", end_date="2015-01-20") } get_premium_export } \keyword{data} fitbitScraper/man/get_intraday_data.Rd0000644000176200001440000000160313073713347017570 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_intraday_data.R \name{get_intraday_data} \alias{get_intraday_data} \title{Get intraday data from fitbit.com} \usage{ get_intraday_data(cookie, what = "steps", date) } \arguments{ \item{cookie}{Cookie returned after login, specifically the "u" cookie} \item{what}{What data you wish to be returned. Options include "steps", "distance", "floors", "active-minutes", "calories-burned", "heart-rate"} \item{date}{Date in YYYY-MM-DD format} } \value{ A dataframe with two columns: \item{time}{A POSIXct time value} \item{data}{The data column corresponding to the choice of "what"} } \description{ Get intraday data from fitbit using cookie returned from login function } \examples{ \dontrun{ get_intraday_data(cookie, what="steps", date="2015-01-20") } get_intraday_data } \keyword{data} fitbitScraper/man/login.Rd0000644000176200001440000000137113073713347015237 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/login.R \name{login} \alias{login} \title{Login to fitbit.com and get cookie} \usage{ login(email, password, rememberMe = FALSE) } \arguments{ \item{email}{Email address used to login to fitbit.com} \item{password}{Password used to login to fitbit.com} \item{rememberMe}{Value for rememberMe during login, default is FALSE, but changing to TRUE may help with login issues} } \value{ A string containing the cookie that is returned after login at www.fitbit.com } \description{ Get the login cookie after login at www.fitbit.com } \examples{ \dontrun{ cookie <- login(email="corynissengmail.com", password="mypasswordhere") } login } \keyword{login} fitbitScraper/LICENSE0000644000176200001440000000005313073713347014066 0ustar liggesusersYEAR: 2014 COPYRIGHT HOLDER: Cory Nissen