[英]GET xAPI statements from a LRS
Have a look at the code below.看看下面的代码。
My objective is to GET xAPI statements from a Learning Record Store (LRS).我的目标是从学习记录存储 (LRS) 中获取 xAPI 语句。
The code is able to GET the first 100 xAPI statements from the LRS - 100 is the maximum amount of statements displayed per page - but not the ones after that.该代码能够从 LRS 获取前 100 个 xAPI 语句 - 100 是每页显示的最大语句数 - 但不是之后的语句。
To solve said problem, I tried to create a loop where I make use of a counter to obtain the next 100 statements and so on.为了解决上述问题,我尝试创建一个循环,在该循环中我使用计数器来获取接下来的 100 条语句等等。 However, I ran into trouble.
然而,我遇到了麻烦。 The current code does not save the next 100 xAPI statements.
当前代码不会保存接下来的 100 个 xAPI 语句。 It simply saves the first 100 over and over.
它只是一遍又一遍地保存前 100 个。 How do I fix this?
我该如何解决?
If you need any more information, let me know.如果您需要更多信息,请告诉我。
output <- data.frame()
counter <- 001L
base <- "https://lrs.com/servlet/ekp/xAPI/statements?from="
url <- paste0(base,counter)
while (TRUE) {
res <- tryCatch({
dat <- GET(url, authenticate(username, password, type = "basic"))
dat <- content(dat, "text", encoding = "UTF-8")
fromJSON(dat, flatten = TRUE)
},error = function(e) NULL)
if (length(res$statements) == 0) break
output <- bind_rows(output, res$statements)
counter <- counter + 100L
print(counter)
}
output <- do.call(rbind, output)
The url
does not change, it should be included inside the while
loop. url
不会改变,它应该包含在while
循环中。
while (TRUE) {
url <- paste0(base,counter)
res <- tryCatch({
dat <- GET(url, authenticate(username, password, type = "basic"))
dat <- content(dat, "text", encoding = "UTF-8")
fromJSON(dat, flatten = TRUE)
},error = function(e) NULL)
if (length(res$statements) == 0) break
output <- bind_rows(output, res$statements)
counter <- counter + 100L
print(counter)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.