# links #https://www.programmableweb.com/news/how-to-access-any-restful-api-using-r-language/how-to/2017/07/21 #https://www.r-bloggers.com/accessing-apis-from-r-and-a-little-r-programming/ # link to genius sport for help https://developer.geniussports.com/warehouse/rest/index_basketball.html # link to check results that gives the genius sport reading https://www.fibalivestats.com/u/FIPDP/1362614/sc.html # packages used rm(list=ls()) ## ------------------------------------------------------------------------ setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) ## ------- listofpackages <- c("httr", "jsonlite", "lubridate") for (j in listofpackages){ if(sum(installed.packages()[, 1] == j) == 0) { install.packages(j) } library(j, character.only = T) } options(stringsAsFactors = FALSE) #get list of matches for C GOLD competition data url <- "https://api.wh.geniussports.com" path <- "v1/basketball/competitions/25992/matches?ak=a0b2d4dc4d72567cbfc591ae256f5a06&limit=500" raw.result <- GET(url = url, path = path) View(raw.result) this.raw.content <- rawToChar(raw.result$content) nchar(this.raw.content) substr(this.raw.content, 1, 100) matches.CGOLD <- fromJSON(this.raw.content) matches.CGOLD.df <- do.call(what = "rbind", args = lapply(matches.CGOLD, as.data.frame)) #specific match data:2PT, 3PT, note the limit of records url <- "https://api.wh.geniussports.com" path <- "v1/basketball/matches/1362614/actions?ak=a0b2d4dc4d72567cbfc591ae256f5a06&actionTypes=2pt%2C3pt&limit=500" raw.result <- GET(url = url, path = path) View(raw.result) this.raw.content <- rawToChar(raw.result$content) nchar(this.raw.content) substr(this.raw.content, 1, 100) data.1362614 <- fromJSON(this.raw.content) data.1362614.df <- do.call(what = "rbind", args = lapply(data.1362614, as.data.frame))