Skip to main content

I use an R script to retrieve my personal activity data from Strava using the API. I use the following code, that, in the past, always gave me data on average and max heart rates, but now these have disappeared for some reason:
 

while (TRUE) {
req <- httr::GET(
url = "https://www.strava.com/api/v3/athlete/activities",
config = token,
query = list(per_page = 200, page = page)
)

# Convert JSON to dataframe
activity_data <- fromJSON(content(req, as = "text"), flatten = TRUE)

# Stop if no data found
if (length(activity_data) == 0) {break}

# Append data to dataframe
if (nrow(df) == 0) {df <- activity_data} else {
common_cols <- intersect(names(df), names(activity_data))
df <- rbind(dfd, common_cols, drop = FALSE], activity_datat, common_cols, drop = FALSE])}

# Turn to next page
page <- page + 1
}

Anyone has an idea why the heart rate data is missing?

I’ve solved it myself. For some reason the “common_cols” approach I was using, removed these attributes from the activity_data. I replaced those lines of code with:

df <- bind_rows(df, activity_data)

 


Reply