Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Last active November 23, 2017 14:16
Show Gist options
  • Select an option

  • Save mrdwab/e0f4c02b581e8b2f559b to your computer and use it in GitHub Desktop.

Select an option

Save mrdwab/e0f4c02b581e8b2f559b to your computer and use it in GitHub Desktop.
getDataList <- function(owner) {
require(gWidgets)
options(guiToolkit="tcltk")
username = ginput("Enter your username: ")
password = ginput("Enter your password: ")
url <- "curl -X GET https://kc.kobotoolbox.org/api/v1/data"
cmd <- sprintf("%s.csv?owner=%s -u %s:%s", url, owner, username, password)
read.csv(text = system(cmd, intern = TRUE, ignore.stderr = TRUE))
}
getDataList("mrdwab")
getData <- function(dataID) {
require(gWidgets)
require(data.table)
options(guiToolkit="tcltk")
username = ginput("Enter your username: ")
password = ginput("Enter your password: ")
url <- "curl -X GET https://kc.kobotoolbox.org/api/v1/data"
cmd <- sprintf("%s/%s.csv -u %s:%s", url, dataID, username, password)
x <- tempfile()
writeLines(system(cmd, intern = TRUE, ignore.stderr = TRUE), con = x)
fread(x)
}
getData("18878")
library(httr)
x <- GET("https://kc.kobotoolbox.org/api/v1/data/18878.csv", authenticate("mrdwab", "*********"))
fread(rawToChar(x[["content"]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment