fawda123 / rStrava

Functions to access data from Strava's v3 API.
154 stars 31 forks source link

get_activity_streams - using repeat to get multiple activites #74

Closed TD604 closed 4 years ago

TD604 commented 4 years ago

hi,

im trying to loop through a list of of activity Id's to compile a table of all my activity streams ..

it will read the first one from the list and then when i get to the second id it gives me the following error [1] 3019821xxx Error in get_streams(stoken, id = ., request = "activities", types = types, : Not Found (HTTP 404).

to make sure it is showing the correct project id i get it to print it into the console first as you can see above. im not sure if this error is a user error (im new to R) or a limitation of get_activity_streams

but any help with this would be great.. thanks here is my code.

`# load packages ####
library(rStrava) # devtools::install_github('fawda123/rStrava')
library(gganimate) # devtools::install_github('dgrtwo/gganimate')
library(dplyr)
library(tidyr)
library(purrr)
library(sp)
library(raster)
require(tcltk)

# Strava key
app_name <- 
app_client_id <- 
app_secret <- 
Account_ID <-  # get this from URL when on my profile in strava

# create strava token
stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, app_scope="activity:read_all"))

#----------------------------------------------------- COLLECT DATA -----------------------------------------------------------------
# Athlete Personal Info
myinfo <- get_athlete(stoken, id = Account_ID)
myinfo[myinfo == "NULL"] <- 0

# get activity list for user.. 

my_acts <- get_activity_list(stoken) # Raw data dump
acts_data <- compile_activities(my_acts) # Sort the data out

# get streams for the first activity in my_acts

Activities_ID <- (acts_data[23])
nrow(Activities_ID)
N <- nrow(Activities_ID) #list legnth
i1 <- 1

repeat
    {
        #print(i1)    # print row number
        id_x <- (i[i1])
    print(id_x) # print id
    strms_data <- get_activity_streams(my_acts, stoken, id = id_x)  
    print(strms_data)
    i1 = i1 + 1 # incremtent up by 1
    if (i1 > 2){ # less the list length
        break
    }
}`
TD604 commented 4 years ago

ok - i figured out the issue .. i forgot to filler out none running activities...