Last active
November 23, 2017 14:16
-
-
Save mrdwab/e0f4c02b581e8b2f559b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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